From: Rick DeNatale Date: 2008-04-29T20:30:39+09:00 Subject: Re: References in Ruby On Tue, Apr 29, 2008 at 7:02 AM, Marcin Tyman wrote: > Hi guys, > > I was quite a bit confused when write following code: > > a = 10 > b = a > a = 50 > > puts b # -> puts 10 > > Why?? Since everything is a reference in Ruby I expected "puts 50". Well not everything IS a reference in Ruby. I think you are suffering from a variation of the common nuby problem of misunderstanding the distinction between variables and objects. Objects have identity and state, sometimes that state is changeable (only by sending the object a message). Variables refer to objects. Variables DON"T refer to other objects. A variable gets bound to a particular object by assignment, only that variable's binding gets change by the assignment. Let's step through your little program code variables objects a = 10 a ------------------> 10 ^ b = a b----------------------+ This is the situation after the first two lines. But after the third we have: a = 50 a -------------------> 50 b--------------------> 10 This article might help: http://talklikeaduck.denhaven2.com/articles/2006/09/13/on-variables-values-and-objects -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/