The Ruby Way, Second Edition: Solutions and Techniques in Ruby Programming (2nd Edition)

 

   

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


   
 

Категории