Class: SyntaxTree::PinnedVarRef
- Inherits:
-
Object
- Object
- SyntaxTree::PinnedVarRef
- Defined in:
- lib/syntax_tree.rb
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.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#value ⇒ Object
readonly
- VarRef
-
the value of this node.
Instance Method Summary collapse
- #child_nodes ⇒ 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.
13055 13056 13057 13058 13059 |
# File 'lib/syntax_tree.rb', line 13055 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
13053 13054 13055 |
# File 'lib/syntax_tree.rb', line 13053 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
13050 13051 13052 |
# File 'lib/syntax_tree.rb', line 13050 def location @location end |
#value ⇒ Object (readonly)
- VarRef
-
the value of this node
13047 13048 13049 |
# File 'lib/syntax_tree.rb', line 13047 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
13061 13062 13063 |
# File 'lib/syntax_tree.rb', line 13061 def child_nodes [value] end |
#format(q) ⇒ Object
13065 13066 13067 13068 13069 13070 |
# File 'lib/syntax_tree.rb', line 13065 def format(q) q.group do q.text("^") q.format(value) end end |
#pretty_print(q) ⇒ Object
13072 13073 13074 13075 13076 13077 13078 13079 13080 13081 |
# File 'lib/syntax_tree.rb', line 13072 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
13083 13084 13085 13086 |
# File 'lib/syntax_tree.rb', line 13083 def to_json(*opts) { type: :pinned_var_ref, value: value, loc: location, cmts: comments } .to_json(*opts) end |