summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2009-12-18 17:32:38 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2009-12-18 17:32:38 -0800
commit348d95c4a4e5bf59ad6b7a1f0952d94ade0f5f63 (patch)
tree393114ac72526747e32575a1849b0f00af67bbbf /lib
parent71ded831a1e47af0609e5c2e44f519dcf9a078d2 (diff)
downloadpsych-348d95c4a4e5bf59ad6b7a1f0952d94ade0f5f63.zip
more refactors for smaller codes
Diffstat (limited to 'lib')
-rw-r--r--lib/psych/visitors/yaml_tree.rb55
1 files changed, 24 insertions, 31 deletions
diff --git a/lib/psych/visitors/yaml_tree.rb b/lib/psych/visitors/yaml_tree.rb
index ee2fcf0..5562f14 100644
--- a/lib/psych/visitors/yaml_tree.rb
+++ b/lib/psych/visitors/yaml_tree.rb
@@ -28,17 +28,6 @@ module Psych
raise TypeError, "Can't dump #{target.class}"
end
- def visit_Psych_Set o
- @stack.push append register(o, Nodes::Mapping.new(nil, '!set', false))
-
- o.each do |k,v|
- accept k
- accept v
- end
-
- @stack.pop
- end
-
def visit_Psych_Omap o
seq = Nodes::Sequence.new(nil, '!omap', false)
register(o, seq)
@@ -138,37 +127,30 @@ module Psych
append Nodes::Scalar.new formatted
end
- def visit_Date o
- append Nodes::Scalar.new o.to_s
- end
-
def visit_Rational o
- @stack.push append Nodes::Mapping.new(nil,'!ruby/object:Rational',false)
- ['denominator', o.denominator, 'numerator', o.numerator].each do |m|
- accept m
+ map = append Nodes::Mapping.new(nil, '!ruby/object:Rational', false)
+ [
+ 'denominator', o.denominator.to_s,
+ 'numerator', o.numerator.to_s
+ ].each do |m|
+ map.children << Nodes::Scalar.new(m)
end
- @stack.pop
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
+ map = append Nodes::Mapping.new(nil, '!ruby/object:Complex', false)
+
+ ['real', o.real.to_s, 'image', o.image.to_s].each do |m|
+ map.children << Nodes::Scalar.new(m)
end
- @stack.pop
end
def visit_Integer o
append Nodes::Scalar.new o.to_s
end
-
- def visit_TrueClass o
- append Nodes::Scalar.new o.to_s
- end
-
- def visit_FalseClass o
- append Nodes::Scalar.new o.to_s
- end
+ alias :visit_TrueClass :visit_Integer
+ alias :visit_FalseClass :visit_Integer
+ alias :visit_Date :visit_Integer
def visit_Float o
if o.nan?
@@ -243,6 +225,17 @@ module Psych
@stack.pop
end
+ def visit_Psych_Set o
+ @stack.push append register(o, Nodes::Mapping.new(nil, '!set', false))
+
+ o.each do |k,v|
+ accept k
+ accept v
+ end
+
+ @stack.pop
+ end
+
def visit_Array o
@stack.push append register(o, Nodes::Sequence.new)
o.each { |c| accept c }