PI
is a constant that belongs to the Math
module. Constants are accessed using the ::
operator:
Math::PI
I believe that it is called a region resolution operator. It can also allow class methods, so you can definitely write:
Math::sin
A point operator sends messages to objects, which is a fancy way of saying that it calls methods. PI
is a constant, so you cannot access it this way. Math.PI
equivalent to Math.send :PI
, which does not work, since Math
does not respond_to? :PI
respond_to? :PI
. Of course you can fix this:
def Math.PI Math::PI end Math.PI
With method_missing
you can even make it work with any constant:
def Math.method_missing(method, *arguments, &block) Math.const_get method, *arguments, &block end Math.PI Math.E
source share