diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2009-09-29 20:53:20 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2009-09-29 20:53:20 -0700 |
commit | 3383117e1955e007d78d3f4a76a551031d6d456d (patch) | |
tree | 1c90d30e56186ed32e0bb315a2a9d087dfecc925 /lib | |
parent | 5ae604004516bc5944c38eee539b022bd7cf4820 (diff) | |
download | psych-3383117e1955e007d78d3f4a76a551031d6d456d.zip |
WE'LL DO IT LIVE
Diffstat (limited to 'lib')
-rw-r--r-- | lib/psych/visitors/emitter.rb | 12 | ||||
-rw-r--r-- | lib/psych/visitors/to_ruby.rb | 12 | ||||
-rw-r--r-- | lib/psych/visitors/visitor.rb | 7 |
3 files changed, 12 insertions, 19 deletions
diff --git a/lib/psych/visitors/emitter.rb b/lib/psych/visitors/emitter.rb index 3e33095..45ebef5 100644 --- a/lib/psych/visitors/emitter.rb +++ b/lib/psych/visitors/emitter.rb @@ -5,35 +5,35 @@ module Psych @handler = Psych::Emitter.new io end - visitor_for(Nodes::Stream) do |o| + def visit_Psych_Nodes_Stream o @handler.start_stream o.encoding o.children.each { |c| c.accept self } @handler.end_stream end - visitor_for(Nodes::Document) do |o| + def visit_Psych_Nodes_Document o @handler.start_document o.version, o.tag_directives, o.implicit o.children.each { |c| c.accept self } @handler.end_document o.implicit_end end - visitor_for(Nodes::Scalar) do |o| + def visit_Psych_Nodes_Scalar o @handler.scalar o.value, o.anchor, o.tag, o.plain, o.quoted, o.style end - visitor_for(Nodes::Sequence) do |o| + def visit_Psych_Nodes_Sequence o @handler.start_sequence o.anchor, o.tag, o.implicit, o.style o.children.each { |c| c.accept self } @handler.end_sequence end - visitor_for(Nodes::Mapping) do |o| + def visit_Psych_Nodes_Mapping o @handler.start_mapping o.anchor, o.tag, o.implicit, o.style o.children.each { |c| c.accept self } @handler.end_mapping end - visitor_for(Nodes::Alias) do |o| + def visit_Psych_Nodes_Alias o @handler.alias o.anchor end end diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb index a37c294..06ab5d1 100644 --- a/lib/psych/visitors/to_ruby.rb +++ b/lib/psych/visitors/to_ruby.rb @@ -8,7 +8,7 @@ module Psych @st = {} end - visitor_for(Nodes::Scalar) do |o| + def visit_Psych_Nodes_Scalar o @st[o.anchor] = o.value if o.anchor case o.tag when 'tag:yaml.org,2002:null' @@ -18,23 +18,23 @@ module Psych end end - visitor_for(Nodes::Sequence) do |o| + def visit_Psych_Nodes_Sequence o o.children.map { |c| c.accept self } end - visitor_for(Nodes::Mapping) do |o| + def visit_Psych_Nodes_Mapping o Hash[*o.children.map { |c| c.accept self }] end - visitor_for(Nodes::Document) do |o| + def visit_Psych_Nodes_Document o o.root.accept self end - visitor_for(Nodes::Stream) do |o| + def visit_Psych_Nodes_Stream o o.children.map { |c| c.accept self } end - visitor_for(Nodes::Alias) do |o| + def visit_Psych_Nodes_Alias o @st[o.anchor] end end diff --git a/lib/psych/visitors/visitor.rb b/lib/psych/visitors/visitor.rb index 8bc1965..ccbd0d0 100644 --- a/lib/psych/visitors/visitor.rb +++ b/lib/psych/visitors/visitor.rb @@ -1,13 +1,6 @@ module Psych module Visitors class Visitor - def self.visitor_for *klasses, &block - klasses.each do |klass| - method_name = klass.name.split('::').join('_') - define_method(:"visit_#{method_name}", block) - end - end - def accept target method_name = target.class.name.split('::').join('_') send(:"visit_#{method_name}", target) |