Class: SyntaxTree::PinnedVarRef

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.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

Instance Method Summary collapse

Constructor Details

#initialize(value:, location:, comments: []) ⇒ PinnedVarRef

Returns a new instance of PinnedVarRef.



11150
11151
11152
11153
11154
# File 'lib/syntax_tree/node.rb', line 11150

def initialize(value:, location:, comments: [])
  @value = value
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



11148
11149
11150
# File 'lib/syntax_tree/node.rb', line 11148

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



11145
11146
11147
# File 'lib/syntax_tree/node.rb', line 11145

def location
  @location
end

#valueObject (readonly)

VarRef

the value of this node



11142
11143
11144
# File 'lib/syntax_tree/node.rb', line 11142

def value
  @value
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



11156
11157
11158
# File 'lib/syntax_tree/node.rb', line 11156

def child_nodes
  [value]
end

#deconstruct_keys(keys) ⇒ Object



11162
11163
11164
# File 'lib/syntax_tree/node.rb', line 11162

def deconstruct_keys(keys)
  { value: value, location: location, comments: comments }
end

#format(q) ⇒ Object



11166
11167
11168
11169
11170
11171
# File 'lib/syntax_tree/node.rb', line 11166

def format(q)
  q.group do
    q.text("^")
    q.format(value)
  end
end

#pretty_print(q) ⇒ Object



11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
# File 'lib/syntax_tree/node.rb', line 11173

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



11184
11185
11186
11187
11188
11189
11190
11191
# File 'lib/syntax_tree/node.rb', line 11184

def to_json(*opts)
  {
    type: :pinned_var_ref,
    value: value,
    loc: location,
    cmts: comments
  }.to_json(*opts)
end