# Where is Fixnum#power! coming from?

**URL:** <https://www.ruby-forum.com/t/where-is-fixnum-power-coming-from/90212>\
**Category:** Ruby\
**Created:** [March 29, 2006, 9:25pm UTC](https://www.ruby-forum.com/t/where-is-fixnum-power-coming-from/90212 "2006-03-29T21:25:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [March 29, 2006, 9:25pm UTC](https://www.ruby-forum.com/t/where-is-fixnum-power-coming-from/90212/1 "2006-03-29T21:25:36Z")

</div>

Hi all,

Ruby 1.8.4

I realize there’s a Fixnum#power! method defined in rational.rb, but it  
appears  
that Fixnum has that method available to it whether or not I require  
rational.rb. I looked through the Ruby source and didn’t see anything.

djberge@~-710\>irb  
irb(main):001:0\> Fixnum.instance\_methods(false).grep(/power/)  
=\> [“rpower”, “power!”]

So, where the heck is it coming from?

Thanks,

Dan

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [March 29, 2006, 9:37pm UTC](https://www.ruby-forum.com/t/where-is-fixnum-power-coming-from/90212/2 "2006-03-29T21:37:53Z")

</div>

On Mar 29, 2006, at 9:22 PM, Daniel B. wrote:

> I realize there’s a Fixnum#power! method defined in rational.rb,  
> but it appears that Fixnum has that method available to it whether  
> or not I require rational.rb. I looked through the Ruby source and  
> didn’t see anything.
> 
> djberge@~-710\>irb  
> irb(main):001:0\> Fixnum.instance\_methods(false).grep(/power/)  
> =\> [“rpower”, “power!”]
> 
> So, where the heck is it coming from?

$ irb -rubygems

> 2.power!(3)  
> =\> 8  
> exit  
> $ irb  
> 2.power!(3)  
> NoMethodError: undefined method `power!’ for 2:Fixnum  
> from (irb):1  
> from :0

Are you requiring rubygems?

– Daniel

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [March 29, 2006, 9:47pm UTC](https://www.ruby-forum.com/t/where-is-fixnum-power-coming-from/90212/3 "2006-03-29T21:47:00Z")

</div>

Daniel B. wrote:

> Hi all,
> 
> Ruby 1.8.4
> 
> I realize there’s a Fixnum#power! method defined in rational.rb, but it  
> appears that Fixnum has that method available to it whether or not I  
> require rational.rb. I looked through the Ruby source and didn’t see  
> anything.

numeric.c:  
flo\_pow(x, y)…  
fix\_pow(x, y)…

and then:  
rb\_define\_method(rb\_cFixnum, “**", fix\_pow, 1);  
rb\_define\_method(rb\_cFloat, "**”, flo\_pow, 1);

and then in rational.rb:

class Fixnum  
alias power! \*\*  
end

are You sure irb doesnt use rational.rb ?

lopex

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [March 29, 2006, 11:51pm UTC](https://www.ruby-forum.com/t/where-is-fixnum-power-coming-from/90212/4 "2006-03-29T23:51:04Z")

</div>

Daniel B. wrote:

> Daniel H. wrote:
> 
> > > 
> > 
> > ```
> > from :0
> > 
> > ```
> > 
> > Are you requiring rubygems?
> > 
> > – Daniel
> 
> Aha! I’m not explicitly require’ing it, but my $RUBYOPT was set. Once  
> I unset  
> it, I got the expected error.

FYI:

RubyGems uses time.rb  
time.rb uses parsedate.rb  
parsedate.rb uses date/format.rb  
date/format.rb uses rational.rb

–  
– Jim W.

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [March 29, 2006, 9:40pm UTC](https://www.ruby-forum.com/t/where-is-fixnum-power-coming-from/90212/5 "2006-03-29T21:40:54Z")

</div>

Daniel H. wrote:

> > 
> 
> ```
> from :0
> 
> ```
> 
> Are you requiring rubygems?
> 
> – Daniel

Aha! I’m not explicitly require’ing it, but my $RUBYOPT was set. Once  
I unset  
it, I got the expected error.

Thanks,

Dan
