Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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-referen...



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: