From: David L Altenburg Date: 2008-03-21T07:26:22+09:00 Subject: Re: Delcaring a foo[] method Howdy, On Mar 20, 2008, at 4:56 PM, Alex Wayne wrote: > I am trying to define a method that you call like this: > > @obj.foo[123] > > I thought I knew how to do this. I tried to setup the method like so: > > def foo[](value) > value * 2 > end > Close. You actually want to override the method named "[]" (and maybe "[]="). So, something like this: class Foo def [](index) # logic here end def []=(index, value) # do some stuff end end So, for the call you want to make work: > @obj.foo[123] @obj.foo needs to return an object with "[]" defined. HTH, David