Class: Ast::Merge::NodeTyping::Wrapper
- Inherits:
-
Object
- Object
- Ast::Merge::NodeTyping::Wrapper
- Defined in:
- lib/ast/merge/node_typing.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.
65 66 67 68 |
# File 'lib/ast/merge/node_typing.rb', line 65 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.
72 73 74 75 76 77 78 |
# File 'lib/ast/merge/node_typing.rb', line 72 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.
59 60 61 |
# File 'lib/ast/merge/node_typing.rb', line 59 def merge_type @merge_type end |
#node ⇒ Object (readonly)
Returns The original node being wrapped.
56 57 58 |
# File 'lib/ast/merge/node_typing.rb', line 56 def node @node end |
Instance Method Details
#==(other) ⇒ Object
Forward equality check to the wrapped node.
97 98 99 100 101 102 103 |
# File 'lib/ast/merge/node_typing.rb', line 97 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.
111 112 113 |
# File 'lib/ast/merge/node_typing.rb', line 111 def eql?(other) self == other end |
#hash ⇒ Object
Forward hash to the wrapped node.
106 107 108 |
# File 'lib/ast/merge/node_typing.rb', line 106 def hash [@node, @merge_type].hash end |
#inspect ⇒ Object
Forward inspect to show both the type and node.
116 117 118 |
# File 'lib/ast/merge/node_typing.rb', line 116 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.
81 82 83 |
# File 'lib/ast/merge/node_typing.rb', line 81 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.
86 87 88 |
# File 'lib/ast/merge/node_typing.rb', line 86 def typed_node? true end |
#unwrap ⇒ Object
Unwrap to get the original node.
92 93 94 |
# File 'lib/ast/merge/node_typing.rb', line 92 def unwrap @node end |