Method Calls and Parentheses


Ruby Way
By Hal Fulton
Slots : 1.0
Table of Contents

Ruby does not always require the use of parentheses to evaluate methods, unless it's necessary to avoid ambiguities.


 def f(x)  print x**2 end f 3     # 9 

However, if parentheses are used near a method, then Ruby will associate them with the method and expect an argument list inside. An expression is a valid argument.


 f (2+3)*4   # 100 f((2+3)*4)   # 576 




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

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: