summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/psych/ruby.rb6
-rw-r--r--lib/psych/visitors/to_ruby.rb14
2 files changed, 16 insertions, 4 deletions
diff --git a/lib/psych/ruby.rb b/lib/psych/ruby.rb
index 6258e81..8831811 100644
--- a/lib/psych/ruby.rb
+++ b/lib/psych/ruby.rb
@@ -3,12 +3,10 @@ require 'rational'
require 'date'
[
- Object, String, Class, Hash, Array, NilClass, Float,
- FalseClass, TrueClass, Range, Complex, Rational, Date
+ Object, String, Class, Hash, Array, NilClass, Float, FalseClass, TrueClass,
+ Range, Complex, Rational, Date, Time, Regexp
# Struct
# Exception
- # Regexp
- # Time
].each do |klass|
klass.send(:remove_method, :to_yaml) rescue NameError
end
diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb
index 40236ce..ab8ef52 100644
--- a/lib/psych/visitors/to_ruby.rb
+++ b/lib/psych/visitors/to_ruby.rb
@@ -22,6 +22,20 @@ module Psych
Complex(o.value)
when "!ruby/object:Rational"
Rational(o.value)
+ when "!ruby/regexp"
+ o.value =~ /^\/(.*)\/([mix]*)$/
+ source = $1
+ options = 0
+ lang = nil
+ ($2 || '').split('').each do |option|
+ case option
+ when 'x' then options |= Regexp::EXTENDED
+ when 'i' then options |= Regexp::IGNORECASE
+ when 'm' then options |= Regexp::MULTILINE
+ else lang = option
+ end
+ end
+ Regexp.new(*[source, options, lang].compact)
when "!ruby/range"
args = o.value.split(/([.]{2,3})/, 2).map { |s|
accept Nodes::Scalar.new(s)