From: Robert Klemme Date: 2012-04-17T22:36:39+09:00 Subject: Re: Why doesn't Fixnum#to_d exist? On Sun, Apr 15, 2012 at 7:48 PM, Chad Perrin wrote: > On Sun, Apr 15, 2012 at 05:35:12AM +0900, Josh Cheek wrote: >> On Sat, Apr 14, 2012 at 11:45 AM, Chad Perrin wrote: >> > On Sat, Apr 14, 2012 at 07:23:34AM +0900, Mark Campbell wrote: >> > > >> > > Yes, that file has the String#to_d, Float#to_d and Rational#to_d. >> > > Fixnum#to_d is not present. >> > >> > Strange.  It appears you're right.  I can do 1.to_d, but I don't know >> > what class has the method when I use it like that. >> >> You can ask the method for its owner to find out >> 1.method(:to_d).owner # => Integer > > Thanks.  That's the method I was trying to remember, but it wouldn't come > to me. > > It's pretty strange how this works, though: > >    >> Integer.methods.include? :to_d >    => false Integer.methods will return methods of the instance Integer (i.e. the class object)! You rather want Integer.instance_methods. >    >> 1.method(:to_d).owner >    => Integer > > . . . so, because I was using the Integer.methods.include? approach > earlier, I didn't find it in Integer either.  Shouldn't the class report > the method when asked even if it's added by a mixin or straight-up > monkeypatch? See above. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/