diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2009-10-08 15:50:48 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2009-10-08 15:50:48 -0700 |
commit | 734a4046b5ac58a21559d43d7d44ddfa3a25cfa5 (patch) | |
tree | b259beddf61a6b71a1e244463618a39fdcc3548c /lib | |
parent | 190735daf6e8ace3f1e6fc7ccf91938e30e8040b (diff) | |
download | psych-734a4046b5ac58a21559d43d7d44ddfa3a25cfa5.zip |
supporting legacy structs
Diffstat (limited to 'lib')
-rw-r--r-- | lib/psych/visitors/to_ruby.rb | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb index 2f6c3b6..2f94be8 100644 --- a/lib/psych/visitors/to_ruby.rb +++ b/lib/psych/visitors/to_ruby.rb @@ -86,9 +86,22 @@ module Psych h = Hash[*o.children.map { |c| accept c }].to_a if klassname && klassname.length > 1 - s = klassname.sub(/^:/,'').split('::').inject(Object) { |k,sub| - k.const_get sub - }.allocate + name = klassname.sub(/^:/, '') + s = nil + retried = false + + begin + s = name.split('::').inject(Object) { |k,sub| + k.const_get sub + }.allocate + rescue NameError => ex + name = "Struct::#{name}" + unless retried + retried = true + retry + end + raise ex + end h.each { |k,v| s.send("#{k}=", v) } s else |