From: Marnen Laibow-Koser Date: 2010-02-04T22:54:18+09:00 Subject: Re: hooking subscript operations in a hash Ralph Shnelvar wrote: > RN> Is env['X'] = 'Y' the same as env[]=('X','Y') ? > RN> Since you defined a method with def []= so I think env[]=('X','Y') > is > RN> easier for understanding. > > First ... I think you meant > env[]={'X', 'Y'} > (braces instead of parenthesis) But you are wrong. It's just like any other method call: object.method(args) so env.[]=('X', 'Y') But never do it this way. env['X'] = 'Y' is far clearer. > > The first form > env[]={'X', 'Y'} > means > Create No. It won't create env. > and/or replace a hash table Hash, not hash table. > called "env" and stuff it with an > index of 'X' and a value of 'Y' > > The second form > env['X'] = 'Y' > means > Take an existing hash table called "env" and add/replace the index 'X' > in that table with the value 'Y' No. The two forms are 100% equivalent. Best, --  Marnen Laibow-Koser http://www.marnen.org marnen@marnen.org -- Posted via http://www.ruby-forum.com/.