summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2009-10-05 14:14:39 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2009-10-05 14:14:39 -0700
commita5aa707138e05d42b7448c1ab2e229ac887506e5 (patch)
treea999c1bc407517adcd78b76afd1c80161ace2378 /lib
parent3d54485fc149b65344db0272df0ed1820bbb03f3 (diff)
downloadpsych-a5aa707138e05d42b7448c1ab2e229ac887506e5.zip
fixing complex numbers in 1.9
Diffstat (limited to 'lib')
-rw-r--r--lib/psych/ruby.rb1
-rw-r--r--lib/psych/visitors/to_ruby.rb7
-rw-r--r--lib/psych/visitors/yast_builder.rb6
3 files changed, 8 insertions, 6 deletions
diff --git a/lib/psych/ruby.rb b/lib/psych/ruby.rb
index ae5dbce..e68632b 100644
--- a/lib/psych/ruby.rb
+++ b/lib/psych/ruby.rb
@@ -1,4 +1,5 @@
require 'complex'
+require 'rational'
[
Object, String, Class, Hash, Array, NilClass, Float,
diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb
index da94ebb..7cfe333 100644
--- a/lib/psych/visitors/to_ruby.rb
+++ b/lib/psych/visitors/to_ruby.rb
@@ -14,6 +14,7 @@ module Psych
@st[o.anchor] = o.value if o.anchor
return o.value if ['!str', 'tag:yaml.org,2002:str'].include?(o.tag)
+ return Complex(o.value) if o.tag == "!ruby/object:Complex"
return o.value if o.quoted
token = ScalarScanner.new(o.value).tokenize
@@ -36,15 +37,15 @@ module Psych
def visit_Psych_Nodes_Mapping o
case o.tag
- when 'ruby/range'
+ when '!ruby/range'
h = Hash[*o.children.map { |c| accept c }]
Range.new(h['begin'], h['end'], h['excl'])
- when 'ruby/object:Complex'
+ when '!ruby/object:Complex'
h = Hash[*o.children.map { |c| accept c }]
Complex(h['real'], h['image'])
- when 'ruby/object:Rational'
+ when '!ruby/object:Rational'
h = Hash[*o.children.map { |c| accept c }]
Rational(h['numerator'], h['denominator'])
diff --git a/lib/psych/visitors/yast_builder.rb b/lib/psych/visitors/yast_builder.rb
index a886af4..c0396e2 100644
--- a/lib/psych/visitors/yast_builder.rb
+++ b/lib/psych/visitors/yast_builder.rb
@@ -22,7 +22,7 @@ module Psych
end
def visit_Rational o
- @stack.push append Nodes::Mapping.new(nil,'ruby/object:Rational',false)
+ @stack.push append Nodes::Mapping.new(nil,'!ruby/object:Rational',false)
['denominator', o.denominator, 'numerator', o.numerator].each do |m|
accept m
end
@@ -30,7 +30,7 @@ module Psych
end
def visit_Complex o
- @stack.push append Nodes::Mapping.new(nil, 'ruby/object:Complex', false)
+ @stack.push append Nodes::Mapping.new(nil, '!ruby/object:Complex', false)
['real', o.real, 'image', o.image].each do |m|
accept m
end
@@ -71,7 +71,7 @@ module Psych
end
def visit_Range o
- @stack.push append Nodes::Mapping.new(nil, 'ruby/range', false)
+ @stack.push append Nodes::Mapping.new(nil, '!ruby/range', false)
['begin', o.begin, 'end', o.end, 'excl', o.exclude_end?].each do |m|
accept m
end