# \* operator, Float

**URL:** <https://www.ruby-forum.com/t/operator-float/192177>\
**Category:** Ruby\
**Created:** [July 25, 2010, 7:02pm UTC](https://www.ruby-forum.com/t/operator-float/192177 "2010-07-25T19:02:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![industrial\_ghetto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/d07c76/32.png) [@industrial\_ghetto](https://www.ruby-forum.com/u/industrial_ghetto)\
**Post date:** [July 25, 2010, 7:02pm UTC](https://www.ruby-forum.com/t/operator-float/192177/1 "2010-07-25T19:02:56Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![industrial\_ghetto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/d07c76/32.png) [@industrial\_ghetto](https://www.ruby-forum.com/u/industrial_ghetto)\
**Post date:** [July 25, 2010, 8:25pm UTC](https://www.ruby-forum.com/t/operator-float/192177/2 "2010-07-25T20:25:53Z")

</div>

Ð˜Ð²Ð°Ð½ Ð¡Ñ‚Ð°ÑˆÐºÐ¾ 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

---

<div class="post-metadata">

**Author:** ![industrial\_ghetto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/d07c76/32.png) [@industrial\_ghetto](https://www.ruby-forum.com/u/industrial_ghetto)\
**Post date:** [July 25, 2010, 10:08pm UTC](https://www.ruby-forum.com/t/operator-float/192177/3 "2010-07-25T22:08:50Z")

</div>

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("\*")

---

<div class="post-metadata">

**Author:** ![industrial\_ghetto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/d07c76/32.png) [@industrial\_ghetto](https://www.ruby-forum.com/u/industrial_ghetto)\
**Post date:** [July 26, 2010, 12:51am UTC](https://www.ruby-forum.com/t/operator-float/192177/4 "2010-07-26T00:51:00Z")

</div>

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
