Class: Ast::Merge::NodeTyping::Wrapper
- Inherits:
-
Object
- Object
- Ast::Merge::NodeTyping::Wrapper
- Defined in:
- lib/ast/merge/node_typing/wrapper.rb
Overview
Node wrapper that adds a merge_type attribute to an existing node.
This uses a simple delegation pattern to preserve all original node
behavior while adding the merge_type.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#merge_type ⇒ Symbol
readonly
The custom merge type for this node.
-
#node ⇒ Object
readonly
The original node being wrapped.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Forward equality check to the wrapped node.
-
#eql?(other) ⇒ Boolean
Forward eql? to the wrapped node.
-
#hash ⇒ Object
Forward hash to the wrapped node.
-
#initialize(node, merge_type) ⇒ Wrapper
constructor
Create a new node type wrapper.
-
#inspect ⇒ Object
Forward inspect to show both the type and node.
-
#method_missing(method, *args, &block) ⇒ Object
Delegate all unknown methods to the wrapped node.
-
#respond_to_missing?(method, include_private = false) ⇒ Boolean
Check if the wrapped node responds to a method.
-
#typed_node? ⇒ Boolean
Returns true to indicate this is a node type wrapper.
-
#unwrap ⇒ Object
Unwrap to get the original node.
Constructor Details
#initialize(node, merge_type) ⇒ Wrapper
Create a new node type wrapper.
20 21 22 23 |
# File 'lib/ast/merge/node_typing/wrapper.rb', line 20 def initialize(node, merge_type) @node = node @merge_type = merge_type end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Delegate all unknown methods to the wrapped node.
This allows the wrapper to be used transparently in place of the node.
27 28 29 30 31 32 33 |
# File 'lib/ast/merge/node_typing/wrapper.rb', line 27 def method_missing(method, *args, &block) if @node.respond_to?(method) @node.send(method, *args, &block) else super end end |
Instance Attribute Details
#merge_type ⇒ Symbol (readonly)
Returns The custom merge type for this node.
14 15 16 |
# File 'lib/ast/merge/node_typing/wrapper.rb', line 14 def merge_type @merge_type end |
#node ⇒ Object (readonly)
Returns The original node being wrapped.
11 12 13 |
# File 'lib/ast/merge/node_typing/wrapper.rb', line 11 def node @node end |
Instance Method Details
#==(other) ⇒ Object
Forward equality check to the wrapped node.
52 53 54 55 56 57 58 |
# File 'lib/ast/merge/node_typing/wrapper.rb', line 52 def ==(other) if other.is_a?(Wrapper) @node == other.node && @merge_type == other.merge_type else @node == other end end |
#eql?(other) ⇒ Boolean
Forward eql? to the wrapped node.
66 67 68 |
# File 'lib/ast/merge/node_typing/wrapper.rb', line 66 def eql?(other) self == other end |
#hash ⇒ Object
Forward hash to the wrapped node.
61 62 63 |
# File 'lib/ast/merge/node_typing/wrapper.rb', line 61 def hash [@node, @merge_type].hash end |
#inspect ⇒ Object
Forward inspect to show both the type and node.
71 72 73 |
# File 'lib/ast/merge/node_typing/wrapper.rb', line 71 def inspect "#<NodeTyping::Wrapper merge_type=#{@merge_type.inspect} node=#{@node.inspect}>" end |
#respond_to_missing?(method, include_private = false) ⇒ Boolean
Check if the wrapped node responds to a method.
36 37 38 |
# File 'lib/ast/merge/node_typing/wrapper.rb', line 36 def respond_to_missing?(method, include_private = false) @node.respond_to?(method, include_private) || super end |
#typed_node? ⇒ Boolean
Returns true to indicate this is a node type wrapper.
41 42 43 |
# File 'lib/ast/merge/node_typing/wrapper.rb', line 41 def typed_node? true end |
#unwrap ⇒ Object
Unwrap to get the original node.
47 48 49 |
# File 'lib/ast/merge/node_typing/wrapper.rb', line 47 def unwrap @node end |