Explain why the last line in the below code prints “hello world”. What does this demonstrate?
def change(param) param << " world" end greeting = "hello" change(greeting) puts greeting
The last line here prints “hello world” because even though the variable greeting is set as “hello”, when the method was run it was given that variable as a parameter and the code in the method mutated the caller. This changed the orignal value of greeting to “hello world”. This demonstrates mutating the caller.