diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-01-15 21:06:30 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-01-15 21:06:30 -0800 |
commit | 79b1fb4a6f7aa18f0ce3056cf65400c46ca2d07b (patch) | |
tree | cc33df4f7d2d31d0cd181e56a8c821c9ccf76f4a /lib | |
parent | 7e67046a46ebaef74b701dd19209d3854c5ecc2b (diff) | |
download | psych-79b1fb4a6f7aa18f0ce3056cf65400c46ca2d07b.zip |
reducing loops, resolving classes
Diffstat (limited to 'lib')
-rw-r--r-- | lib/psych/visitors/to_ruby.rb | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb index 6d6dae0..f156d87 100644 --- a/lib/psych/visitors/to_ruby.rb +++ b/lib/psych/visitors/to_ruby.rb @@ -91,7 +91,7 @@ module Psych string = members.delete 'str' init_with(string, members.map { |k,v| [k.to_s.sub(/^@/, ''),v] }) when /^!ruby\/struct:?(.*)?$/ - klass = resolve_class($1) + klass = resolve_class($1) if klass s = klass.allocate @@ -125,13 +125,12 @@ module Psych e = build_exception((resolve_class($1) || Exception), h.delete('message')) init_with(e, h) - e when '!set', 'tag:yaml.org,2002:set' set = Psych::Set.new @st[o.anchor] = set if o.anchor - o.children.map { |c| accept c }.each_slice(2) do |k,v| - set[k] = v + o.children.each_slice(2) do |k,v| + set[accept(k)] = accept(v) end set @@ -146,15 +145,13 @@ module Psych when /^!ruby\/object:?(.*)?$/ name = $1 || 'Object' h = Hash[*o.children.map { |c| accept c }] - s = name.split('::').inject(Object) { |k,sub| - k.const_get sub - }.allocate + s = (resolve_class(name) || Object).allocate init_with(s, h) else hash = {} @st[o.anchor] = hash if o.anchor - o.children.map { |c| accept c }.each_slice(2) { |k,v| - hash[k] = v + o.children.each_slice(2) { |k,v| + hash[accept(k)] = accept(v) } hash end |