summaryrefslogtreecommitdiff
path: root/ext/psych/lib/psych/visitors/visitor.rb
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-11-02 21:24:54 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-11-02 21:24:54 +0000
commitad9aa5368fb6a34294fb9cd4e48aed3bae244dbf (patch)
treed4f4fe12c012e889a9dd4c5e98335e6adcb0819e /ext/psych/lib/psych/visitors/visitor.rb
parent8114da9e6be525e0d4bd5107f8f2aa97c5560bc6 (diff)
* ext/psych/lib/psych/visitors/visitor.rb (accept): switch to
a dispatch cache rather than case / when statement. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29670 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/psych/lib/psych/visitors/visitor.rb')
-rw-r--r--ext/psych/lib/psych/visitors/visitor.rb21
1 files changed, 11 insertions, 10 deletions
diff --git a/ext/psych/lib/psych/visitors/visitor.rb b/ext/psych/lib/psych/visitors/visitor.rb
index 3471c43dfa1..0e33128f013 100644
--- a/ext/psych/lib/psych/visitors/visitor.rb
+++ b/ext/psych/lib/psych/visitors/visitor.rb
@@ -11,16 +11,17 @@ module Psych
end
def accept target
- case target
- when Psych::Nodes::Scalar then visit_Psych_Nodes_Scalar target
- when Psych::Nodes::Mapping then visit_Psych_Nodes_Mapping target
- when Psych::Nodes::Sequence then visit_Psych_Nodes_Sequence target
- when Psych::Nodes::Alias then visit_Psych_Nodes_Alias target
- when Psych::Nodes::Document then visit_Psych_Nodes_Document target
- when Psych::Nodes::Stream then visit_Psych_Nodes_Stream target
- else
- raise "Can't handle #{target}"
- end
+ visit target
+ end
+
+ private
+
+ DISPATCH = Hash.new do |hash, klass|
+ hash[klass] = "visit_#{klass.name.gsub('::', '_')}"
+ end
+
+ def visit target
+ send DISPATCH[target.class], target
end
end
end