From 0086400dd75e73152429f9acf2fce984d8f46e02 Mon Sep 17 00:00:00 2001 From: Alberto Almagro Date: Fri, 7 Dec 2018 00:02:38 +0100 Subject: [PATCH] Expand metaprogramming for Symbol, Slash and Dot. This first started with moving type method inside `ActionDispatch::Journey::Nodes::Symbol`. `AD::Journey::Nodes::Symbol#type` was generated dynamically with an `each` block. While this is OK for classes like `AD::Journey::Nodes::Slash` or `AD::Journey::Nodes::Dot` which don't have further implementation, all other classes containing more logic have this method defined in their class body. This patch does the same in this case. On code review process @kamipo suggested to fully expand over metaprogramming for Slash and Dot classes, a topic on which I agree with him. --- .../lib/action_dispatch/journey/nodes/node.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/actionpack/lib/action_dispatch/journey/nodes/node.rb b/actionpack/lib/action_dispatch/journey/nodes/node.rb index 32f632800c..086d6a3e07 100644 --- a/actionpack/lib/action_dispatch/journey/nodes/node.rb +++ b/actionpack/lib/action_dispatch/journey/nodes/node.rb @@ -65,12 +65,12 @@ def initialize(x = Object.new) def literal?; false; end end - %w{ Symbol Slash Dot }.each do |t| - class_eval <<-eoruby, __FILE__, __LINE__ + 1 - class #{t} < Terminal; - def type; :#{t.upcase}; end - end - eoruby + class Slash < Terminal # :nodoc: + def type; :SLASH; end + end + + class Dot < Terminal # :nodoc: + def type; :DOT; end end class Symbol < Terminal # :nodoc: @@ -89,6 +89,7 @@ def default_regexp? regexp == DEFAULT_EXP end + def type; :SYMBOL; end def symbol?; true; end end -- GitLab