Skip to content

Instantly share code, notes, and snippets.

@Fryguy
Created December 15, 2011 19:08
Show Gist options
  • Save Fryguy/1482361 to your computer and use it in GitHub Desktop.
Save Fryguy/1482361 to your computer and use it in GitHub Desktop.
psych doesn't handle instance variables in subclasses of Hash
diff --git a/test/psych/test_hash.rb b/test/psych/test_hash.rb
index 4bd4edf..b000226 100644
--- a/test/psych/test_hash.rb
+++ b/test/psych/test_hash.rb
@@ -5,6 +5,10 @@ module Psych
class X < Hash
end
+ class Y < Hash
+ attr_accessor :val
+ end
+
def setup
super
@hash = { :a => 'b' }
@@ -16,6 +20,12 @@ module Psych
assert_equal X, x.class
end
+ def test_subclass_with_attributes
+ y = Psych.load Psych.dump Y.new.tap {|y| y.val = 1}
+ assert_equal Y, y.class
+ assert_equal 1, y.val
+ end
+
def test_map
x = Psych.load "--- !map:#{X} { }\n"
assert_equal X, x.class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment