Created
July 23, 2013 03:06
-
-
Save flarnie/6059566 to your computer and use it in GitHub Desktop.
demo of YAML deep dup trick
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'yaml' | |
#the deep dup YAML cheat: | |
#nested arrays and hashes | |
complexity = [1, {:here => "is", :a => {:nested => "Hash!"}}, [ 2, 3, 4, [5, 6, 7]]] | |
p complexity | |
complex_yaml = complexity.to_yaml | |
p complex_yaml | |
new_complexity = YAML.load(complex_yaml) | |
new_complexity[1] = "CHANGED" | |
puts "Old version" | |
p complexity | |
puts "New version" | |
p new_complexity | |
#new_complexity is a new complete copy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment