Class: Querly::Pattern::Expr::Vcall

Inherits:
Base
  • Object
show all
Defined in:
lib/querly/pattern/expr.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#==, #attributes

Constructor Details

#initialize(name:) ⇒ Vcall

Returns a new instance of Vcall.



307
308
309
# File 'lib/querly/pattern/expr.rb', line 307

def initialize(name:)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



305
306
307
# File 'lib/querly/pattern/expr.rb', line 305

def name
  @name
end

Instance Method Details

#=~(pair) ⇒ Object



311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/querly/pattern/expr.rb', line 311

def =~(pair)
  node = pair.node

  if node.type == :lvar
    # We don't want lvar without method call
    # Skips when the node is not receiver of :send
    parent_node = pair.parent&.node
    if parent_node && parent_node.type == :send && parent_node.children.first.equal?(node)
      test_node(node)
    end
  else
    test_node(node)
  end
end

#test_node(node) ⇒ Object



326
327
328
329
330
331
332
333
# File 'lib/querly/pattern/expr.rb', line 326

def test_node(node)
  case node&.type
  when :send
    node.children[1] == name
  when :lvar
    node.children.first == name
  end
end