I’m running Ruby 1.9.3 on Windows XP. According to the docs[1], #to_d
is defined for BigDecimal, Float, Rational, String, and Integer (which
is a superclass of Fixnum and Bignum).
W dniu 14 kwietnia 2012 15:19 użytkownik Mark C. [email protected] napisał:
I totally agree with you, however, as I mentioned in my first post, I am
using 1.8.7, which does not have this. In fact, 1.9.2 doesn’t have it
either.
Ruby 1.8.7 is nearing it’s EOL[1], so I suggest upgrading soon (if you
can). You can report issues and feature requests on Ruby’s bug
tracker: http://bugs.ruby-lang.org/
W dniu 15 kwietnia 2012 19:48 użytkownik Chad P. [email protected] napisał:
. . . 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?
. . . 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?
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?