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>
|
Tue Nov 2 21:46:52 2010 Kouhei Sutou <kou@cozmixng.org>
|
||||||
|
|
||||||
* NEWS: fix a typo.
|
* NEWS: fix a typo.
|
||||||
|
|
|
@ -11,16 +11,17 @@ module Psych
|
||||||
end
|
end
|
||||||
|
|
||||||
def accept target
|
def accept target
|
||||||
case target
|
visit target
|
||||||
when Psych::Nodes::Scalar then visit_Psych_Nodes_Scalar target
|
end
|
||||||
when Psych::Nodes::Mapping then visit_Psych_Nodes_Mapping target
|
|
||||||
when Psych::Nodes::Sequence then visit_Psych_Nodes_Sequence target
|
private
|
||||||
when Psych::Nodes::Alias then visit_Psych_Nodes_Alias target
|
|
||||||
when Psych::Nodes::Document then visit_Psych_Nodes_Document target
|
DISPATCH = Hash.new do |hash, klass|
|
||||||
when Psych::Nodes::Stream then visit_Psych_Nodes_Stream target
|
hash[klass] = "visit_#{klass.name.gsub('::', '_')}"
|
||||||
else
|
end
|
||||||
raise "Can't handle #{target}"
|
|
||||||
end
|
def visit target
|
||||||
|
send DISPATCH[target.class], target
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue