diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2009-10-05 16:45:38 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2009-10-05 16:45:38 -0700 |
commit | efa7a36b3c151bf958b92ebb714a2c98fe4d5ebe (patch) | |
tree | b77e5647bc0a20e9085d560f95082f1dee20c308 | |
parent | a5aa707138e05d42b7448c1ab2e229ac887506e5 (diff) | |
download | psych-efa7a36b3c151bf958b92ebb714a2c98fe4d5ebe.zip |
fixing rational strings
-rw-r--r-- | lib/psych/visitors/to_ruby.rb | 1 | ||||
-rw-r--r-- | test/visitors/test_to_ruby.rb | 5 |
2 files changed, 6 insertions, 0 deletions
diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb index 7cfe333..6aea934 100644 --- a/lib/psych/visitors/to_ruby.rb +++ b/lib/psych/visitors/to_ruby.rb @@ -15,6 +15,7 @@ module Psych return o.value if ['!str', 'tag:yaml.org,2002:str'].include?(o.tag) return Complex(o.value) if o.tag == "!ruby/object:Complex" + return Rational(o.value) if o.tag == "!ruby/object:Rational" return o.value if o.quoted token = ScalarScanner.new(o.value).tokenize diff --git a/test/visitors/test_to_ruby.rb b/test/visitors/test_to_ruby.rb index 3cb1ead..63a5006 100644 --- a/test/visitors/test_to_ruby.rb +++ b/test/visitors/test_to_ruby.rb @@ -45,6 +45,11 @@ module Psych node = Nodes::Scalar.new '3+4i', nil, "!ruby/object:Complex" assert_equal Complex(3, 4), node.to_ruby end + + def test_rational_string + node = Nodes::Scalar.new '1/2', nil, "!ruby/object:Rational" + assert_equal Rational(1, 2), node.to_ruby + end end def test_integer |