Skip to content

Instantly share code, notes, and snippets.

@kv109
Created October 14, 2010 09:28
Show Gist options
  • Save kv109/625937 to your computer and use it in GitHub Desktop.
Save kv109/625937 to your computer and use it in GitHub Desktop.
Local and global variable in method's body
def method(arg)
#<<arg>> is not a local copy of global variable - <<string>> and <<arg>> are the same object.
arg.upcase!
arg.object_id #We will return object_id to see if it's true
end
string = 'John'
id = string.object_id
id2 = method(string)
id == id2 #=> true
string #=> 'JOHN'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment