I think what's confusing him is that the outer hash isn't within {}s
-- he doesn't realize that the {}s aren't *always* necessary, that
there are implicit hashes in some method calls.
Here y is the key and another hash, {:x => X.new}, is the value. And
within this hash again, x is the key and X.new is the value.
More accurately the symbol :y is the key (splitting hairs)...
I think what's confusing him is that the outer hash isn't within {}s
-- he doesn't realize that the {}s aren't *always* necessary, that
there are implicit hashes in some method calls.
Technically speaking Marnen's reply ("The braces can be omitted when
there is no
ambiguity.") is more accurate.
I also wanted to point out that there is a new "optional" syntax for
hash key/value pairs introduced in Ruby 1.9:
{ y } same as { :x => y } same as y same as :x => y
So what's the business about ambiguity?
my_obj.my_method(:x => y, :a => b)
Was the intent of the above to call my_method with a single hash with
two keys and two values, or to pass two single key hashes to my_method?
Sometimes the {} are required to remove ambiguity:
my_obj.my_method({ :x => y, :a => b })
1 hash argument containing 2 key/value pairs
my_obj.my_method({ :x => y }, { :a => b })
2 hash arguments each with a single key/value pair
my_obj.my_method([ { :x => y }, { :a => b } ])
1 array argument containing two hash elements, each having a single key/value pair