From: matz@... (Yukihiro Matsumoto) Date: 2001-05-28T01:08:26+09:00 Subject: [ruby-talk:15807] Re: is it possible to dynamically coerce objects types in Ruby? Hi, In message "[ruby-talk:15804] is it possible to dynamically coerce objects types in Ruby?" on 01/05/28, Mirian Crzig Lennox 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.