Created
November 10, 2009 17:48
-
-
Save sigmonsays/231085 to your computer and use it in GitHub Desktop.
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
y$ cat pass-by-ref.rb | |
def pbr_int(i) | |
i = 5 | |
end | |
def pbr_str(s) | |
s = "another value" | |
end | |
def pbr_list(l) | |
l << 5 | |
end | |
def pbr_hash(h) | |
h['a'] = 'bar' | |
end | |
puts "== int ==" | |
i = 2 | |
pbr_int(i) | |
puts "i = #{i}" | |
puts "== str ==" | |
s = "string value" | |
pbr_str(s) | |
puts "s = #{s}" | |
puts "== hash ==" | |
h = {} | |
h['a'] = 'foo' | |
pbr_hash(h) | |
puts "h = #{h.inspect}" | |
puts "== list ==" | |
l = [] | |
l << 1 | |
pbr_list(l) | |
puts "l = #{l.inspect}" | |
================================== | |
$ ruby $_ | |
== int == | |
i = 2 | |
== str == | |
s = string value | |
== hash == | |
h = {"a"=>"bar"} | |
== list == | |
l = [1, 5] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment