提交 0086400d 编写于 作者: A Alberto Almagro

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.
上级 b86f65a8
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册