object reference in ruby

you pass the value of the variable in to the method, however the value of the
variable is _always_ a reference to an object.

In order to get a object that won’t change out from under you, you need to dup or clone the object you’re passed, thus giving an object that nobody else has a reference to.

b=[]
=> []
>> a=b
=> []
>> b< <1
>> a
=> [1]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s