From: Marcelo Date: 2008-04-23T21:27:25+09:00 Subject: Re: PickAxe - Understanding [] on SongList On Wed, Apr 23, 2008 at 6:07 AM, Mohnish Chaudhary wrote: > What I don't understand is how is "list[0]" working ? The syntax of > the method specified is "[](index)", so how come can we pass the > index within the braces instead of after it i.e shouldn't it be > "list.[](0)"? But strangely, both work! That's Ruby syntax sugar. When you define a method called "[]" which takes one argument you can call it like this: instance[arg] You can also define "[]=" taking two arguments which you can call it like this: instance[arg1] = arg2 You can define "[]" taking two arguments and call it like this: instance[arg1, arg2] And so on... Marcelo