# Precedence of \*\*

**URL:** <https://www.ruby-forum.com/t/precedence-of/115441>\
**Category:** Ruby\
**Created:** [September 25, 2007, 11:18am UTC](https://www.ruby-forum.com/t/precedence-of/115441 "2007-09-25T11:18:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pandemic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8491ac/32.png) [@pandemic](https://www.ruby-forum.com/u/pandemic)\
**Post date:** [September 25, 2007, 11:18am UTC](https://www.ruby-forum.com/t/precedence-of/115441/1 "2007-09-25T11:18:40Z")

</div>

I recently discovered that the precedence of \*\* seems to be at  
variance with the documentation. All tables of precedence for Ruby  
that I have found (including in the pickaxe) have listed \*\* as just  
above that of the four unary operators + - ! and ~. However, ruby  
actually parses 3 of these as higher precedence than \*\*. This is most  
obvious when using ParseTree:

$ irb -rubygems  
irb(main):001:0\> require ‘parse\_tree’  
WARNING: overridding bool on  
/usr/lib/ruby/gems/1.8/gems/ParseTree-2.0.2/lib/parse\_tree.rb:244  
=\> true  
irb(main):002:0\> ParseTree.translate '!i**2’  
=\> [:call, [:not, [:vcall, :i]], :**, [:array, [:lit, 2]]]  
irb(main):003:0\> ParseTree.translate '~i**2’  
=\> [:call, [:call, [:vcall, :i], :~], :**, [:array, [:lit, 2]]]  
irb(main):004:0\> ParseTree.translate '+i**2’  
=\> [:call, [:call, [:vcall, :i], :+@], :**, [:array, [:lit, 2]]]  
irb(main):005:0\> ParseTree.translate '-i**2’  
=\> [:call, [:call, [:vcall, :i], :**, [:array, [:lit, 2]]], :-@]

Unary minus actually comes out as lower precedence than \*\*, but the  
other three unary ops all bind more tightly. I have seen this using  
1.8.2 on Debian, and 1.8.5 and 1.8.6 on Ubuntu.

I see now that the table of precedence in parse.y actually has +, ~,  
and ! as lower precedence than \*\*. I thought it was going to be  
something less obvious… Was it intended to be this way, and the  
documentation is wrong?
