On 2009-04-14, Florian Kaufmann <sensorflo / gmail.com> wrote:

> The ruby book tells me that programming ruby, types doesn't matter so
> much, what matters is to what messages an object responds. Thus I
> tried the following, thinking that to_i is needed so an object can be
> used as an subscript index.

#to_i is not sufficient, but #to_int is:

$ irb
irb(main):001:0> foo = Object.new
=> #<Object:0xb7c14064>
irb(main):002:0> [ 34, 45 ][foo]
TypeError: can't convert Object into Integer
        from (irb):2:in `[]'
        from (irb):2
irb(main):003:0> def foo.to_int ; 1 ; end
=> nil
irb(main):004:0> [ 34, 45 ][foo]
=> 45

Regards,

Jeremy Henty