Created
November 19, 2012 06:04
-
-
Save jeffreyiacono/4109181 to your computer and use it in GitHub Desktop.
call by reference (ruby / python)
This file contains hidden or 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
| some_guy = 'Fred' | |
| first_names = [] | |
| first_names.append(some_guy) | |
| another_list_of_names = first_names | |
| another_list_of_names.append('George') | |
| some_guy = 'Bill' | |
| print (some_guy, first_names, another_list_of_names) |
This file contains hidden or 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
| some_guy = 'Fred' | |
| first_names = [] | |
| first_names.push(some_guy) | |
| another_list_of_names = first_names | |
| another_list_of_names.push('George') | |
| some_guy = 'Bill' | |
| another_list_of_names[0] = some_guy | |
| print some_guy, first_names, another_list_of_names | |
| puts | |
| __END__ | |
| Bill ["Fred", "George"] ["Fred", "George"] |
This file contains hidden or 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 fetch_super_power_again attrs | |
| if (power = attrs[:super_power]) | |
| puts power | |
| else | |
| puts "couldn't find your super power :/" | |
| end | |
| end | |
| def fetch_super_power attrs | |
| attrs.delete(:super_power) | |
| end | |
| attributes = {:name => 'jeff', :super_power => 'flight'} | |
| puts fetch_super_power(attributes) # flight | |
| puts attributes # {:name => 'jeff'} | |
| fetch_super_power_again attributes # couldn't find your super power :/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment