Using the code below:
variable = puts "hello world".upcase
Why does Ruby automatically puts Hello world in upcase, without the variable first being invoked? I understand that you are setting the function to the variable, and if that variable is called it will return the return value (in this case, nil), but why is it that Ruby runs the method puts "hello world".upcase
almost without permission (have not called it, merely assigned to a variable)?
foo
is a reference to the function objectfoo
, andfoo()
is a call to that function. In Ruby,foo
is a call to the function -- other syntax is needed to get aMethod
object. – Article