summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2009-09-29 20:53:20 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2009-09-29 20:53:20 -0700
commit3383117e1955e007d78d3f4a76a551031d6d456d (patch)
tree1c90d30e56186ed32e0bb315a2a9d087dfecc925 /lib
parent5ae604004516bc5944c38eee539b022bd7cf4820 (diff)
downloadpsych-3383117e1955e007d78d3f4a76a551031d6d456d.zip
WE'LL DO IT LIVE
Diffstat (limited to 'lib')
-rw-r--r--lib/psych/visitors/emitter.rb12
-rw-r--r--lib/psych/visitors/to_ruby.rb12
-rw-r--r--lib/psych/visitors/visitor.rb7
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)