mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
8114da9e6b
commit
ad9aa5368f
2 changed files with 16 additions and 10 deletions
|
@ -1,3 +1,8 @@
|
|||
Tue Nov 2 22:47:08 2010 Aaron Patterson <aaron@tenderlovemaking.com>
|
||||
|
||||
* ext/psych/lib/psych/visitors/visitor.rb (accept): switch to
|
||||
a dispatch cache rather than case / when statement.
|
||||
|
||||
Tue Nov 2 21:46:52 2010 Kouhei Sutou <kou@cozmixng.org>
|
||||
|
||||
* NEWS: fix a typo.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue