From: Dido Sevilla Date: 2005-10-25T10:59:33+09:00 Subject: Re: syntax quickie On 10/24/05, Kev Jackson wrote: > Hi all, > > What exactly does the following do and how can I test it? It looks like > its creating a new value with the key name, but how do you call it? > > def [](name) > @val[name] > end > It's actually Ruby's syntax for operator overloading. An instance of a class that defines this can be "indexed" as though it were an array or hash. Other operators are overriden in the same way, e.g. def +(x) ... end Remember that everything in Ruby is an object, so when you see even something as simple as 1 + 1 in Ruby, that's actually syntactic sugar for 1.+(1), calling the + method for an instance of the Fixnum class.