Making a Copy of an Object : clone « Class « Ruby






Making a Copy of an Object


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

 








Related examples in the same category

1.Create a class dynamically
2.Clone a customized string