@kyanny's blog

My thoughts, my life. Views/opinions are my own.

Numeric#new と Integer#new

Numeric.new はできるけど Integer.new はできない。へー。だからどうしたという。でも「へー」と思ったので書いとく。

$ rvm 1.9.2
$ irb
ruby-1.9.2-p136 :001 > Numeric.new
 => #<Numeric:0x0000000a329a88>
ruby-1.9.2-p136 :002 > Integer.new
NoMethodError: undefined method `new' for Integer:Class
        from (irb):2
        from /home/kyanny/.rvm/rubies/ruby-1.9.2-p136/bin/irb:16:in `<main>'
ruby-1.9.2-p136 :003 > quit
$ rvm 1.8.7
$ irb
ruby-1.8.7-p330 :001 > Numeric.new
 => #<Numeric:0x2ba2e2dc43c0>
ruby-1.8.7-p330 :002 > Integer.new
NoMethodError: undefined method `new' for Integer:Class
        from (irb):2
ruby-1.8.7-p330 :003 > quit