shajin
shajin

Reputation: 3264

Ruby Numeric vs Integer

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

Answers (1)

Andrey Deineko
Andrey Deineko

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

Related Questions