From: Иван Сташко on
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?
--
Posted via http://www.ruby-forum.com/.

From: Marvin Gülker on
Иван Сташко 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/.

From: Ken Bloom on
On Mon, 26 Jul 2010 02:05:48 +0900, Иван Сташко wrote:

> Where is the * operator defined for Float?

use instance_methods, not methods

Float.instance_methods(false).grep("*")

> 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?





--
Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/


From: Иван Сташко on
OK, this is clear.

I was able to get the necessary effect using coerce(). What failed was
...

class Float
def *(o)
if o.class == FooBoo then
o.send(:*,o)
else
super
end
end
end

--
Posted via http://www.ruby-forum.com/.