Class: ImproveYourCode::AST::ASTNodeClassMap
- Inherits:
-
Object
- Object
- ImproveYourCode::AST::ASTNodeClassMap
- Defined in:
- lib/improve_your_code/ast/ast_node_class_map.rb
Instance Method Summary collapse
- #extension_map ⇒ Object
-
#initialize ⇒ ASTNodeClassMap
constructor
A new instance of ASTNodeClassMap.
- #klass_for(type) ⇒ Object
Constructor Details
#initialize ⇒ ASTNodeClassMap
Returns a new instance of ASTNodeClassMap.
9 10 11 |
# File 'lib/improve_your_code/ast/ast_node_class_map.rb', line 9 def initialize @klass_map = {} end |
Instance Method Details
#extension_map ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/improve_your_code/ast/ast_node_class_map.rb', line 21 def extension_map @extension_map ||= begin assoc = SexpExtensions.constants.map do |const| [ const.to_s.sub(/Node$/, '').downcase.to_sym, SexpExtensions.const_get(const) ] end Hash[assoc] end end |
#klass_for(type) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/improve_your_code/ast/ast_node_class_map.rb', line 13 def klass_for(type) klass_map[type] ||= Class.new(Node).tap do |klass| extension = extension_map[type] klass.send :include, extension if extension end end |