RosettaCodeData/Task/Enforced-immutability/Ruby/enforced-immutability-2.rb

9 lines
377 B
Ruby
Raw Permalink Normal View History

2015-02-20 00:35:01 -05:00
# There are two methods in the copy of the object.
msg = "Hello World!".freeze
msg2 = msg.clone # Copies the frozen and tainted state of obj.
msg3 = msg.dup # It doesn't copy the status (frozen, tainted) of obj.
puts msg2 #=> Hello World!
puts msg3 #=> Hello World!
puts msg2.frozen? #=> true
puts msg3.frozen? #=> false