On Thu, Mar 20, 2008 at 4:56 PM, Alex Wayne
<rubyonrails / beautifulpixel.com> wrote:

> I am trying to define a method that you call like this:
>
>   @obj.foo[123]
>
>  I thought I knew how to do this...

For this to work, the "foo" method must return an instance of an
object that defines a "[]" method. So, for example, something like
this:

    class IndexableThing
      def [](index)
        2*index
      end
    end

    class OtherThing
      def foo
        IndexableThing.new
      end
    end

    obj = OtherThing.new
    obj.foo[2] # => returns 4

Hope this helps,

Lyle