Also instead of key.class != Fixnum do !key.kind_of?(Numeric).  (Note that decimals are accepted as index values for Array, hence the change to Numeric).