After passing a reference to an method, any mods using that reference are not visible outside the me

Posted by Jason on Stack Overflow See other posts from Stack Overflow or by Jason
Published on 2010-05-11T03:58:03Z Indexed on 2010/05/11 4:24 UTC
Read the original article Hit count: 352

Filed under:
|
|
|

I am passing the reference of name to *mod_name*, I modify the referenced object from within the method but the change is not visible outside of the method, if I am referring to the same object from all locations how come the value is different depending on where I reference it?

name = "Jason"

puts name.object_id      #19827274

def mod_name(name)
  puts name.object_id    #19827274
  name = "JasonB"
end

puts name.object_id      #19827274

puts name                #Jason

String might be a bad example, but I get the same result even if I use a Fixnum.

© Stack Overflow or respective owner

Related posts about ruby

Related posts about objects