Skip to content

Instantly share code, notes, and snippets.

@kapso
Created June 27, 2012 18:09
Show Gist options
  • Save kapso/3005776 to your computer and use it in GitHub Desktop.
Save kapso/3005776 to your computer and use it in GitHub Desktop.
Ruby parameter passing by value or reference? (its by REF)
class Car
def start(options)
options[:speed] = 60
puts "running @ #{options[:speed]}"
end
end
op = { speed: 50 }
puts op.inspect
Car.new.start op
puts op.inspect
# prints out the following
# {:speed=>50}
# running @ 60
# {:speed=>60}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment