Class: Solargraph::Rspec::Walker::Hook

Inherits:
Object
  • Object
show all
Defined in:
lib/solargraph/rspec/walker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node_type, args, &block) ⇒ Hook

Returns a new instance of Hook.

Parameters:

  • node_type (Symbol)
  • args (Array)
  • block (Proc)


14
15
16
17
18
# File 'lib/solargraph/rspec/walker.rb', line 14

def initialize(node_type, args, &block)
  @node_type = node_type
  @args = args
  @proc = Proc.new(&block)
end

Instance Attribute Details

#node_typeObject (readonly)

Returns the value of attribute node_type.



9
10
11
# File 'lib/solargraph/rspec/walker.rb', line 9

def node_type
  @node_type
end

Instance Method Details

#visit(node) ⇒ void

This method returns an undefined value.

Parameters:

  • node (RubyVM::AbstractSyntaxTree::Node)


22
23
24
25
26
27
28
29
30
31
32
# File 'lib/solargraph/rspec/walker.rb', line 22

def visit(node)
  return unless matches?(node)

  if @proc.arity == 1
    @proc.call(node)
  elsif @proc.arity == 2
    walker = Walker.new(node)
    @proc.call(node, walker)
    walker.walk
  end
end