In Ruby, how can I copy a variable so that changes in the original do not affect the copy?
For example:
phrase1 = "Hello Jim" phrase2 = phrase1 phrase1.gsub!("Hello","Hi") p phrase2 #outputs "Hi Jim" - I want it to remain "Hello Jim"
In this example, two variables point to the same object; I want to create a new object for the second variable, but must first contain the same information.
ruby
Nathan Long Sep 23 '09 at 12:05 2009-09-23 12:05
source share