Created
October 14, 2010 09:28
-
-
Save kv109/625937 to your computer and use it in GitHub Desktop.
Local and global variable in method's body
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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