summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/psych/ruby.rb4
-rw-r--r--lib/psych/visitors/yast_builder.rb4
-rw-r--r--test/visitors/test_yast_builder.rb5
3 files changed, 11 insertions, 2 deletions
diff --git a/lib/psych/ruby.rb b/lib/psych/ruby.rb
index e68632b..6258e81 100644
--- a/lib/psych/ruby.rb
+++ b/lib/psych/ruby.rb
@@ -1,14 +1,14 @@
require 'complex'
require 'rational'
+require 'date'
[
Object, String, Class, Hash, Array, NilClass, Float,
- FalseClass, TrueClass, Range, Complex, Rational
+ FalseClass, TrueClass, Range, Complex, Rational, Date
# Struct
# Exception
# Regexp
# Time
- # Date
].each do |klass|
klass.send(:remove_method, :to_yaml) rescue NameError
end
diff --git a/lib/psych/visitors/yast_builder.rb b/lib/psych/visitors/yast_builder.rb
index c0396e2..9111f8b 100644
--- a/lib/psych/visitors/yast_builder.rb
+++ b/lib/psych/visitors/yast_builder.rb
@@ -21,6 +21,10 @@ module Psych
raise TypeError, "Can't dump #{target.class}"
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|
diff --git a/test/visitors/test_yast_builder.rb b/test/visitors/test_yast_builder.rb
index f5423e9..2f6e443 100644
--- a/test/visitors/test_yast_builder.rb
+++ b/test/visitors/test_yast_builder.rb
@@ -8,6 +8,11 @@ module Psych
@v = Visitors::YASTBuilder.new
end
+ def test_date
+ date = Date.strptime('2002-12-14', '%Y-%m-%d')
+ assert_round_trip date
+ end
+
def test_rational
assert_round_trip Rational(1,2)
end