diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2009-10-07 09:32:58 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2009-10-07 09:32:58 -0700 |
commit | 762d889dc911c43274aa4c00104302d36e883add (patch) | |
tree | 9afd10778aea5ac53001a569d22d7452d7e5709d /lib | |
parent | 2cf1f822b5e44308bb9e5af8ee4d75cfda0b4d9e (diff) | |
download | psych-762d889dc911c43274aa4c00104302d36e883add.zip |
scalar regexp goes to ruby
Diffstat (limited to 'lib')
-rw-r--r-- | lib/psych/ruby.rb | 6 | ||||
-rw-r--r-- | lib/psych/visitors/to_ruby.rb | 14 |
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) |