summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/psych/visitors/to_ruby.rb24
-rw-r--r--lib/psych/visitors/yast_builder.rb3
2 files changed, 13 insertions, 14 deletions
diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb
index 39c9194..fec2614 100644
--- a/lib/psych/visitors/to_ruby.rb
+++ b/lib/psych/visitors/to_ruby.rb
@@ -97,23 +97,12 @@ module Psych
def visit_Psych_Nodes_Mapping o
case o.tag
- when /!ruby\/object(:.*)?$/
- name = $1.sub(/^:/, '')
- h = Hash[*o.children.map { |c| accept c }]
- s = name.split('::').inject(Object) { |k,sub|
- k.const_get sub
- }.allocate
- h.each do |k,v|
- s.instance_variable_set(:"@#{k}", v)
- end
- s
-
- when /!ruby\/struct(:.*)?$/
+ when /!ruby\/struct:?(.*)?$/
klassname = $1
h = Hash[*o.children.map { |c| accept c }].to_a
if klassname && klassname.length > 1
- name = klassname.sub(/^:/, '')
+ name = klassname
s = nil
retried = false
@@ -151,6 +140,15 @@ module Psych
h = Hash[*o.children.map { |c| accept c }]
Rational(h['numerator'], h['denominator'])
+ when /!ruby\/object:?(.*)?$/
+ name = $1.nil? ? 'Object' : $1
+ h = Hash[*o.children.map { |c| accept c }]
+ s = name.split('::').inject(Object) { |k,sub|
+ k.const_get sub
+ }.allocate
+ h.each { |k,v| s.instance_variable_set(:"@#{k}", v) }
+ s
+
else
hash = {}
@st[o.anchor] = hash if o.anchor
diff --git a/lib/psych/visitors/yast_builder.rb b/lib/psych/visitors/yast_builder.rb
index 11e3b34..e8f9891 100644
--- a/lib/psych/visitors/yast_builder.rb
+++ b/lib/psych/visitors/yast_builder.rb
@@ -23,7 +23,8 @@ module Psych
end
def visit_Object o
- tag = ['!ruby/object', o.class.name].join(':')
+ klass = o.class == Object ? nil : o.class.name
+ tag = ['!ruby/object', klass].compact.join(':')
@stack.push append Nodes::Mapping.new(nil, tag, false)
o.instance_variables.each do |iv|
accept iv.to_s.sub(/^@/, '')