Reputation: 3264
In ruby,
115.class => Fixnum < Integer
115.0.class => Float < Numeric
Can someone point of the difference between Integer class and Numeric class?
also, if I want to write some common instance function between Fixnum and Float, in which class I should write?
Upvotes: 0
Views: 2042
Reputation: 52357
Numeric.descendants
#=> [BigDecimal, Date::Infinity, Integer, Fixnum, Float, Bignum, Rational, Complex]
So if you need to define a method for both Fixnum
and Float
you can do it in Numeric (not talking about the open classes monkeypatching issues)
Upvotes: 3