Mikael Høilund
4/29/2008 11:22:00 AM
On Apr 29, 2008, at 13:02, Marcin Tyman wrote:
> a = 10
> b = a
> a = 50
>
> puts b # -> puts 10
>
> Why?? Since everything is a reference in Ruby I expected "puts 50".
That's because you're not changing 50, you're changing a. At the third
line, you're setting a to be a different object than b. Compare to:
>> a = "Hello"
=> "Hello"
>> b = a
=> "Hello"
>> a.upcase!
=> "HELLO"
>> b
=> "HELLO"
Play around with Object#object_id for a better idea of how this works.