Reputation: 4479
I'm writing a Fixnum
class method to_words
that takes any number and translates it to English so,
2.to_words
#=> "two"
2030.to_words
#=> "two thousand thirty"
I would like it to handle all numbers, and there a problem once I get a little past 1 billion:
1000002000.to_words
#=> "one billion two thousand"
1074000000.to_words
#=> NoMethodError
1074000000.class
#=> Bignum
Is there a way to extend my Fixnum.to_words
method to Bignum
?
Upvotes: 1
Views: 61
Reputation: 3053
Both Fixnum
and Bignum
inherit from Integer
, so it would be preferable in your case to define #to_words
on Integer
so either Fixnum
s or Bignum
s would inherit that method.
Upvotes: 5