[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-talk
Subject: Re: * operator, Float
From: Marvin_Gülker <sutniuq () gmx ! net>
Date: 2010-07-25 18:25:55
Message-ID: 2b24106a8b2e42833ffe1dbe10d9bc3d () ruby-forum ! com
[Download RAW message or body]
Иван Сташко wrote:
> Where is the * operator defined for Float?
>
> ree-1.8.7-2010.02 > 3.0.methods.grep "*"
> => ["*"]
> ree-1.8.7-2010.02 > 3.0.class
> => Float
> ree-1.8.7-2010.02 > Float.methods.grep "*"
> => []
> ree-1.8.7-2010.02 > Float.superclass
> => Numeric
> ree-1.8.7-2010.02 > Numeric.methods.grep "*"
> => []
> ree-1.8.7-2010.02 > Numeric.superclass
> => Object
> ree-1.8.7-2010.02 > Object.methods.grep "*"
> => []
> ree-1.8.7-2010.02 > Object.superclass
> => nil
>
> I'm guessing there's a mixin somewhere or this has to do with
> eigenclasses or perhaps a C-module has been mixed-in between Numeric and
> Float. Where do I look at this code?
The way you're trying to find the #* method is wrong. You try to find
Class#*, not Float#*. Try it this way:
irb(main):004:0> Float.public_instance_methods.map(&:to_s).grep("*")
=> ["*"]
irb(main):005:0> Numeric.public_instance_methods.map(&:to_s).grep("*")
=> []
irb(main):006:0>
If Float#* wasn't defined in C code, you could use
Method#source_location to find out where it is defined (at least in Ruby
1.9):
irb(main):006:0> 3.0.method(:*).source_location
=> nil
irb(main):007:0> require "pathname"
=> true
irb(main):008:0> Pathname.new("x").method(:to_s).source_location
=> ["/opt/rubies/ruby-1.9.1-p429/lib/ruby/1.9.1/pathname.rb", 248]
irb(main):009:0>
If #source_location gives you nil, you're dealing with a C method.
Marvin
--
Posted via http://www.ruby-forum.com/.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic