Greetings to all.  I am a newcomer to Ruby and I am exploring the
language.  Here is a question I have which I have not been able to 
find the answer to:

Suppose I have a class which is not an integer, but which I would
like to be able to act like an integer under certain circumstances.
Ideally, I could say something like:

class MyClass < OtherClass
   def to_i
       generate_integer_representation
   end
end

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?

regards,
--Mirian