Skip to content

Instantly share code, notes, and snippets.

Created December 5, 2015 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/c44446aaf91c75dc4835 to your computer and use it in GitHub Desktop.
Save anonymous/c44446aaf91c75dc4835 to your computer and use it in GitHub Desktop.

Say I have a YAML file:

---
foo:
  bar:
  baz:
    - a
    - b

And I want to attempt to loop through an array that might possibly be found as a value for foo['bar'] in Python:

for i in foo['baz']:
  print(i)

Normally, Python would behave as if there is nothing to loop through and continue on from that particular code.

But, with similar code from Ruby:

for i in foo['baz']
   puts i
end

I receive a NoMethodError exception and the script halts entirely. How do you make Ruby behave like the Python example above?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment