Skip to content

Instantly share code, notes, and snippets.

@bradleyd
Last active December 15, 2015 18:19
Show Gist options
  • Select an option

  • Save bradleyd/5303126 to your computer and use it in GitHub Desktop.

Select an option

Save bradleyd/5303126 to your computer and use it in GitHub Desktop.
class Shopper
def initialize(list)
@list = list
end
attr_accessor :list
end
string = "foo"
a = Shopper.new(string)
b = Shopper.new(string)
p a.object_id # => 6504360
p b.object_id # => 6504340
p a.list.object_id # => 6504380
p b.list.object_id # => 6504380
b.list.concat("baz") # => "foobaz"
p b.list # => "foobaz"
p a.list # => "foobaz"
a.list.concat("hello") # => "foobazhello"
p a.list # => "foobazhello"
p b.list # => "foobazhello"
# >> 6504360
# >> 6504340
# >> 6504380
# >> 6504380
# >> "foobaz"
# >> "foobaz"
# >> "foobazhello"
# >> "foobazhello"
@oz

oz commented Apr 3, 2013

Copy link
Copy Markdown

Now try with :

s = "foo"
a = Shopper.new(s)
b = Shopper.new(s)

... and compare s.object_id, with a.list.object_id, and b.list.object_id

@bradleyd

bradleyd commented Apr 3, 2013

Copy link
Copy Markdown
Author

I see the difference. I updated the gist to reflect these differences.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment