From: Morton Goldberg Date: 2007-06-02T12:56:55+09:00 Subject: Re: Is [ ] really a method ? On Jun 1, 2007, at 11:42 PM, Vin Raja wrote: > Hi all, > > Well while running down the text I read that [] (used in case > Arrays and > Hashes) is actually a method called on that Array/hash object and also > that it can be overridden. > > well point taken. > > BUT if this is just another case of operator overloading then how come > we can call > > a[1]='item' > > rather than calling > > a[]1 ='item' > > (Anyways this gave me a syntax error) > Or perhaps it is just another case of Syntactic Sugar? > Or perhaps not, because if that has to be true than the second > statement > should also have been true. > > So Is [] really a method or is a simple grammar token? You are really asking about []= which is a different method than []. And, yes, it really is a method, as is shown by a = ['a'] a.[]=(1, 'b') a # => ["a", "b"] which is the same as a = ['a'] a[1] = 'b' a # => ["a", "b"] Regards, Morton