Class: Rucoa::Nodes::SendNode

Inherits:
Base
  • Object
show all
Defined in:
lib/rucoa/nodes/send_node.rb

Instance Method Summary collapse

Methods inherited from Base

#ancestors, #child_nodes, #descendant_nodes, #each_ancestor, #each_child_node, #each_descendant_node, #include_position?, #initialize, #module_nesting, #namespace, #next_sibling_nodes, #parent, #parent=, #previous_sibling_nodes, #updated

Constructor Details

This class inherits a constructor from Rucoa::Nodes::Base

Instance Method Details

#argumentsArray<Rucoa::Nodes::Base>

Examples:

returns arguments

node = Rucoa::Source.new(
  content: <<~RUBY,
    foo(bar, baz)
  RUBY
  uri: 'file:///path/to/example.rb'
).root_node
expect(node.arguments.map(&:name)).to eq(
  %w[
    bar
    baz
  ]
)

Returns:



20
21
22
# File 'lib/rucoa/nodes/send_node.rb', line 20

def arguments
  children[2..]
end

#blockRucoa::Nodes::BlockNode?

Examples:

returns nil for method call without block

node = Rucoa::Source.new(
  content: <<~RUBY,
    foo
  RUBY
  uri: 'file:///path/to/example.rb'
).node_at(
  Rucoa::Position.new(
    column: 0,
    line: 1
  )
)
expect(node.block).to be_nil

returns block

node = Rucoa::Source.new(
  content: <<~RUBY,
    foo do
      bar
    end
  RUBY
  uri: 'file:///path/to/example.rb'
).node_at(
  Rucoa::Position.new(
    column: 0,
    line: 1
  )
)
expect(node.block).to be_a(Rucoa::Nodes::BlockNode)

Returns:



53
54
55
# File 'lib/rucoa/nodes/send_node.rb', line 53

def block
  parent if called_with_block?
end

#nameString

Examples:

returns method name

node = Rucoa::Source.new(
  content: <<~RUBY,
    foo(bar, baz)
  RUBY
  uri: 'file:///path/to/example.rb'
).root_node
expect(node.name).to eq('foo')

Returns:

  • (String)


66
67
68
# File 'lib/rucoa/nodes/send_node.rb', line 66

def name
  children[1].to_s
end

#receiverRucoa::Nodes::Base?

Examples:

returns nil for receiver-less method call

node = Rucoa::Source.new(
  content: <<~RUBY,
    foo(bar, baz)
  RUBY
  uri: 'file:///path/to/example.rb'
).root_node
expect(node.receiver).to be_nil

returns receiver

node = Rucoa::Source.new(
  content: <<~RUBY,
    foo.bar
  RUBY
  uri: 'file:///path/to/example.rb'
).node_at(
  Rucoa::Position.new(
    column: 4,
    line: 1
  )
)
expect(node.receiver).to be_a(Rucoa::Nodes::SendNode)

Returns:



92
93
94
# File 'lib/rucoa/nodes/send_node.rb', line 92

def receiver
  children[0]
end