Class: SyntaxTree::PinnedVarRef
Overview
PinnedVarRef represents a pinned variable reference within a pattern matching pattern.
case value
in ^variable
end
This can be a plain local variable like the example above. It can also be a a class variable, a global variable, or an instance variable.
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#value ⇒ Object
readonly
- VarRef
-
the value of this node.
Attributes inherited from Node
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:, comments: []) ⇒ PinnedVarRef
constructor
A new instance of PinnedVarRef.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(value:, location:, comments: []) ⇒ PinnedVarRef
Returns a new instance of PinnedVarRef.
10712 10713 10714 10715 10716 |
# File 'lib/syntax_tree/node.rb', line 10712 def initialize(value:, location:, comments: []) @value = value @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
10710 10711 10712 |
# File 'lib/syntax_tree/node.rb', line 10710 def comments @comments end |
#value ⇒ Object (readonly)
- VarRef
-
the value of this node
10707 10708 10709 |
# File 'lib/syntax_tree/node.rb', line 10707 def value @value end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
10718 10719 10720 |
# File 'lib/syntax_tree/node.rb', line 10718 def child_nodes [value] end |
#deconstruct_keys(keys) ⇒ Object
10724 10725 10726 |
# File 'lib/syntax_tree/node.rb', line 10724 def deconstruct_keys(keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
10728 10729 10730 10731 10732 10733 |
# File 'lib/syntax_tree/node.rb', line 10728 def format(q) q.group do q.text("^") q.format(value) end end |
#pretty_print(q) ⇒ Object
10735 10736 10737 10738 10739 10740 10741 10742 10743 10744 |
# File 'lib/syntax_tree/node.rb', line 10735 def pretty_print(q) q.group(2, "(", ")") do q.text("pinned_var_ref") q.breakable q.pp(value) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
10746 10747 10748 10749 10750 10751 10752 10753 |
# File 'lib/syntax_tree/node.rb', line 10746 def to_json(*opts) { type: :pinned_var_ref, value: value, loc: location, cmts: comments }.to_json(*opts) end |