Skip to content

Instantly share code, notes, and snippets.

@jeffreyiacono
Created November 19, 2012 06:04
Show Gist options
  • Select an option

  • Save jeffreyiacono/4109181 to your computer and use it in GitHub Desktop.

Select an option

Save jeffreyiacono/4109181 to your computer and use it in GitHub Desktop.
call by reference (ruby / python)
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)
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"]
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