4 ms·
Not exactly. Let's tweak your example to create a new object in your method. def foo s s = 'foo' end a = 'bar' foo a puts a # => bar The assig
by sciurus 15y ago
Not exactly. Let's tweak your example to create a new object in your method.
def foo s
s = 'foo'
end
a = 'bar'
foo a
puts a
# => bar
The assignment in the method doesn't change the object you "passed" in. Rather than passing by reference, think of Ruby as passing the value of a reference.
For more examples and explanation, see
http://khelll.com/blog/ruby/ruby-pass-by-value-or-by-reference/ http://khelll.com/blog/ruby/ruby-pass-by-value-or-by-referen...