Skip to content

Instantly share code, notes, and snippets.

@flarnie
Created July 23, 2013 03:06
Show Gist options
  • Save flarnie/6059566 to your computer and use it in GitHub Desktop.
Save flarnie/6059566 to your computer and use it in GitHub Desktop.
demo of YAML deep dup trick
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