Hi,

In message "[ruby-talk:15804] is it possible to dynamically coerce objects types in Ruby?"
    on 01/05/28, Mirian Crzig Lennox <mirian / cosmic.com> writes:

|And then I would like Ruby to notice that it has the to_i method
|defined, and so automatically call this when it needs it to act like
|an integer.  For example, assume anArray is an array:
|
|myObj = MyClass.new(...)
|elem = anArray[myObj]
|
|When I try this, Ruby tells me "Failed to convert MyClass to Integer".
|
|Is there a good way around this?

Try 'to_int' which is for that particular purpose, not 'to_i' which is
for explicit conversion to integer.  And when you want something to be
string, try 'to_str'.

							matz.