Custom Search

Making a Copy of an Object - Ruby

April 19, 2008 – 1:11 pm

You want to make a copy of an existing object: a new object that can be modified separately from the original, Use Object#clone - makes a copy of the metaclass and instantiates the copy, instead of instantiating the object’s original class

example how to use clone :

s1 = 'foo'                             # => "foo"
s2 = s1.clone                          # => "foo"
s1[0] = 'b'
[s1, s2]                               # => ["boo","foo"]

Popularity: 12% [?]

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • StumbleUpon
  • Technorati
  • TwitThis
  • E-mail this story to a friend!
  • Print this article!

Tags: ,


Related Posts

Post a Comment