Methods and Dot Notation

 
   

Ruby Way
By Hal Fulton
Slots : 1.0
Table of Contents
 


Dot notation in Ruby is used strictly for method dispatch. The left side is the object or variable, and the right side is the method name. The result is always an object, so you can chain method calls as in Python.

The :: scope operator is needed to access nested modules, classes, and their constants. It can also optionally be used to access a class method.

Methods can also be called without dot notation, in which case Ruby will implicitly use self as the receiver. However, the parser will influence operators implemented as methods and used without dot notation.

 

 print 3 + 4 * 5  # 23 print 3.+(4).*(5) # 35 


   

 

 



The Ruby Way
The Ruby Way, Second Edition: Solutions and Techniques in Ruby Programming (2nd Edition)
ISBN: 0672328844
EAN: 2147483647
Year: 2000
Pages: 119
Authors: Hal Fulton

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net