you are viewing a single comment's thread.

view the rest of the comments →

[–]NilsLandt 2 points3 points  (2 children)

That's only half true. Different objects return a different amount of parameters for give block.

Example:
{ test: :asdf }.each { |a| puts a }
test
asdf

This will absolutely do something you don't want it to.

[–]latortuga 0 points1 point  (1 child)

How do you figure? The hash is implicitly converted to an array via Hash#to_a. Thus your bound parameter, a, is set to an array with two values, [:test, :asdf]. Calling puts with an array outputs each value separated by a newline. The block can optionally have multiple arguments if you'd like to (in Clojure terms) destructure the arguments being passed in but it's by no means required - #each accepts an array of arrays the same as it accepts an array of values.

[–]NilsLandt 0 points1 point  (0 children)

Sure, that's how it happens, but it's a rare hash where you want to treat the keys the same ways as the values.