summaryrefslogtreecommitdiff
path: root/ext/psych
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-12-18 03:44:09 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-12-18 03:44:09 +0000
commitcf2bbc89d26ef29ab33b3a11a71c30ffba35fe2f (patch)
tree91998add7a4b54eb287a784a336ac49db79985aa /ext/psych
parent7cabeff61a25e37517afcdc4fb164a9365f5e30c (diff)
* ext/psych/lib/psych/visitors/to_ruby.rb: BigDecimals can be restored
from YAML. * ext/psych/lib/psych/visitors/yaml_tree.rb: BigDecimals can be dumped to YAML. * test/psych/test_numeric.rb: tests for BigDecimal serialization git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34069 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/psych')
-rw-r--r--ext/psych/lib/psych/visitors/to_ruby.rb3
-rw-r--r--ext/psych/lib/psych/visitors/yaml_tree.rb4
2 files changed, 7 insertions, 0 deletions
diff --git a/ext/psych/lib/psych/visitors/to_ruby.rb b/ext/psych/lib/psych/visitors/to_ruby.rb
index 4267f4d004..bf48f9d029 100644
--- a/ext/psych/lib/psych/visitors/to_ruby.rb
+++ b/ext/psych/lib/psych/visitors/to_ruby.rb
@@ -52,6 +52,9 @@ module Psych
o.value.unpack('m').first
when '!str', 'tag:yaml.org,2002:str'
o.value
+ when '!ruby/object:BigDecimal'
+ require 'bigdecimal'
+ BigDecimal._load o.value
when "!ruby/object:DateTime"
require 'date'
@ss.parse_time(o.value).to_datetime
diff --git a/ext/psych/lib/psych/visitors/yaml_tree.rb b/ext/psych/lib/psych/visitors/yaml_tree.rb
index 523ad77645..f37396602c 100644
--- a/ext/psych/lib/psych/visitors/yaml_tree.rb
+++ b/ext/psych/lib/psych/visitors/yaml_tree.rb
@@ -214,6 +214,10 @@ module Psych
end
end
+ def visit_BigDecimal o
+ @emitter.scalar o._dump, nil, '!ruby/object:BigDecimal', false, false, Nodes::Scalar::ANY
+ end
+
def binary? string
string.encoding == Encoding::ASCII_8BIT ||
string.index("\x00") ||