diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/psych/ruby.rb | 5 | ||||
-rw-r--r-- | lib/psych/visitors/emitter.rb | 8 | ||||
-rw-r--r-- | lib/psych/visitors/to_ruby.rb | 13 | ||||
-rw-r--r-- | lib/psych/visitors/yast_builder.rb | 16 |
4 files changed, 27 insertions, 15 deletions
diff --git a/lib/psych/ruby.rb b/lib/psych/ruby.rb index 1412da5..d4d4e66 100644 --- a/lib/psych/ruby.rb +++ b/lib/psych/ruby.rb @@ -1,13 +1,14 @@ +require 'complex' + [ Object, String, Class, Hash, Array, NilClass, Float, - FalseClass, TrueClass, Range + FalseClass, TrueClass, Range, Complex # Struct # Exception # Regexp # Time # Date # Rational - # Complex ].each do |klass| klass.send(:remove_method, :to_yaml) rescue NameError end diff --git a/lib/psych/visitors/emitter.rb b/lib/psych/visitors/emitter.rb index 45ebef5..0768fbb 100644 --- a/lib/psych/visitors/emitter.rb +++ b/lib/psych/visitors/emitter.rb @@ -7,13 +7,13 @@ module Psych def visit_Psych_Nodes_Stream o @handler.start_stream o.encoding - o.children.each { |c| c.accept self } + o.children.each { |c| accept c } @handler.end_stream end def visit_Psych_Nodes_Document o @handler.start_document o.version, o.tag_directives, o.implicit - o.children.each { |c| c.accept self } + o.children.each { |c| accept c } @handler.end_document o.implicit_end end @@ -23,13 +23,13 @@ module Psych def visit_Psych_Nodes_Sequence o @handler.start_sequence o.anchor, o.tag, o.implicit, o.style - o.children.each { |c| c.accept self } + o.children.each { |c| accept c } @handler.end_sequence end def visit_Psych_Nodes_Mapping o @handler.start_mapping o.anchor, o.tag, o.implicit, o.style - o.children.each { |c| c.accept self } + o.children.each { |c| accept c } @handler.end_mapping end diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb index ef8a279..54e02d6 100644 --- a/lib/psych/visitors/to_ruby.rb +++ b/lib/psych/visitors/to_ruby.rb @@ -22,19 +22,22 @@ module Psych def visit_Psych_Nodes_Sequence o list = [] @st[o.anchor] = list if o.anchor - o.children.each { |c| list.push c.accept self } + o.children.each { |c| list.push accept c } list end def visit_Psych_Nodes_Mapping o case o.tag when 'ruby/range' - h = Hash[*o.children.map { |c| c.accept self }] + h = Hash[*o.children.map { |c| accept c }] Range.new(h['begin'], h['end'], h['excl']) + when 'ruby/object:Complex' + h = Hash[*o.children.map { |c| accept c }] + Complex(h['real'], h['image']) else hash = {} @st[o.anchor] = hash if o.anchor - o.children.map { |c| c.accept self }.each_slice(2) { |k,v| + o.children.map { |c| accept c }.each_slice(2) { |k,v| hash[k] = v } hash @@ -42,11 +45,11 @@ module Psych end def visit_Psych_Nodes_Document o - o.root.accept self + accept o.root end def visit_Psych_Nodes_Stream o - o.children.map { |c| c.accept self } + o.children.map { |c| accept c } end def visit_Psych_Nodes_Alias o diff --git a/lib/psych/visitors/yast_builder.rb b/lib/psych/visitors/yast_builder.rb index 7b5d53b..f6998d2 100644 --- a/lib/psych/visitors/yast_builder.rb +++ b/lib/psych/visitors/yast_builder.rb @@ -21,6 +21,14 @@ module Psych raise TypeError, "Can't dump #{target.class}" end + def visit_Complex o + @stack.push append Nodes::Mapping.new(nil, 'ruby/object:Complex', false) + ['real', o.real, 'image', o.image].each do |m| + accept m + end + @stack.pop + end + def visit_Integer o append Nodes::Scalar.new o.to_s end @@ -57,7 +65,7 @@ module Psych def visit_Range o @stack.push append Nodes::Mapping.new(nil, 'ruby/range', false) ['begin', o.begin, 'end', o.end, 'excl', o.exclude_end?].each do |m| - m.accept self + accept m end @stack.pop end @@ -74,8 +82,8 @@ module Psych @stack.push append map o.each do |k,v| - k.accept self - v.accept self + accept k + accept v end @stack.pop @@ -91,7 +99,7 @@ module Psych @st[o.object_id] = seq @stack.push append seq - o.each { |c| c.accept self } + o.each { |c| accept c } @stack.pop end |