Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Ruby have Numeric.new?

Tags:

oop

ruby

a = Numeric.new  # doesn't take an argument

I can't imagine a use case for this. Can you?

like image 405
steenslag Avatar asked Oct 04 '10 21:10

steenslag


1 Answers

The Class class defines a new instance method. And so the new class method on Numeric is just a holdover from that - it doesn't do anything - think of it as one of those vestigial organs that animals inherit from a distant ancestor - like the appendix on humans.

Note that the subclasses of Numeric such as Fixnum and Float and their kin explictly undefine the new method. I guess they just didn't bother undefining it for Numeric as direct instances of this class never really exist, and it does no harm keeping it around.

like image 141
horseyguy Avatar answered Sep 23 '22 16:09

horseyguy