You are violating Ruby's type conversion protocols in various ways.
First off, your object responds to to_int
, to_float
, to_str
, to_ary
etc. without actually being an integer, a float, a string or an array. The three letter (ahem f-l-o-a-t ahem) versions of those type conversion methods are supposed to be used only in the case where the object in question really absolutely positively is an integer, float, string or array and is just not represented as an instance of Integer
, Float
, String
or Array
.
However, your object isn't an Array
, it's a map. So, it should only respond to to_hash
, if at all.
And secondly, the return value of to_int
, to_float
, to_str
, to_ary
etc. should be an instance of the Integer
, Float
, String
or Array
class.
So, you are implementing methods that you shouldn't even be implementing in the first place and you are returning the wrong value from them. Doing that for something as deeply ingrained in the core of Ruby as its type conversion protocols is bound to wreak all sorts of havoc of which you are only seeing the beginning.