summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
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)