Class: Yoda::AST::SendNode

Inherits:
Node show all
Defined in:
lib/yoda/ast/send_node.rb

Instance Attribute Summary

Attributes inherited from Node

#node

Attributes inherited from Vnode

#comments_by_node, #parent

Instance Method Summary collapse

Methods inherited from Node

#children, #identifier, #initialize, #kind, #source_map

Methods inherited from Vnode

#children, #constant?, #empty?, #identifier, #initialize, #inspect, #inspect_content, #nesting, #present?, #try, #type, #wrap_child

Methods included from Vnode::CommentPositional

#comments_by_vnode, #positionally_nearest_comment, #positionally_nearest_commenting_node

Methods included from Vnode::Positional

#location, #positionally_include?, #positionally_nearest_child, #range, #source_map

Methods included from Vnode::CommentAssociation

#all_nodes_lazy, #associate_comments, #comments, #wrapping?

Methods included from Traversable

#query, #query_all, #query_ancestor, #query_ancestors

Methods included from MethodTraversable

#calc_current_location_method, #including_method, #method?

Methods included from NamespaceTraversable

#calc_current_location_namespace, #full_name, #namespace, #namespace?, #namespace_path, #root?

Constructor Details

This class inherits a constructor from Yoda::AST::Node

Instance Method Details

#argumentsArray<Vnode>

Returns:



20
21
22
# File 'lib/yoda/ast/send_node.rb', line 20

def arguments
  children.slice(2..-1)
end

#arguments_rangeParsing::Range

Returns:



65
66
67
68
69
70
71
# File 'lib/yoda/ast/send_node.rb', line 65

def arguments_range
  @arguments_range ||=
    Parsing::Range.new(
      Parsing::Location.of_ast_location(source_map.selector.end),
      Parsing::Location.of_ast_location(source_map.expression.end).move(row: 0, column: -1),
    )
end

#block_pass_argumentObject



39
40
41
# File 'lib/yoda/ast/send_node.rb', line 39

def block_pass_argument
  arguments.last.type == :block_pass ? arguments.last : nil
end

#dot_rangeParsing::Range?

Returns:



79
80
81
# File 'lib/yoda/ast/send_node.rb', line 79

def dot_range
  @dot_range ||= source_map.dot && Parsing::Range.of_ast_location(source_map.dot)
end

#expanded_argumentsArray<Vnode>

Returns:



25
26
27
28
29
30
31
32
# File 'lib/yoda/ast/send_node.rb', line 25

def expanded_arguments
  block_pass_arguments, arguments_without_block_pass = arguments.partition { |node| node.type == :block_pass }
  if last_argument = arguments_without_block_pass.last
    arguments_without_block_pass.slice(0..-2) + (last_argument.type == :hash ? last_argument.children : [last_argument]) + block_pass_arguments
  else
    arguments_without_block_pass.slice(0..-2) + block_pass_arguments
  end
end

#implicit_receiver?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/yoda/ast/send_node.rb', line 43

def implicit_receiver?
  receiver.empty?
end

#keyword_argumentObject



34
35
36
37
# File 'lib/yoda/ast/send_node.rb', line 34

def keyword_argument
  non_bpass_arguments = arguments.reject { |node| node.type == :block_pass }
  non_bpass_arguments.last&.type == :hash ? non_bpass_arguments.last : nil
end

#next_location_to_dotParsing::Location?

Returns:



84
85
86
# File 'lib/yoda/ast/send_node.rb', line 84

def next_location_to_dot
  source_map.dot && Parsing::Range.of_ast_location(source_map.dot).end_location
end

#offset_in_selector(location) ⇒ Integer

Parameters:

Returns:

  • (Integer)


95
96
97
# File 'lib/yoda/ast/send_node.rb', line 95

def offset_in_selector(location)
  location.offset_from_begin(source_map.selector)[:column]
end

#on_arguments?(location) ⇒ true, false

Parameters:

Returns:

  • (true, false)


60
61
62
# File 'lib/yoda/ast/send_node.rb', line 60

def on_arguments?(location)
  arguments_range.include?(location)
end

#on_dot?(location) ⇒ true, false

Parameters:

Returns:

  • (true, false)


54
55
56
# File 'lib/yoda/ast/send_node.rb', line 54

def on_dot?(location)
  source_map.dot ? dot_range.include?(location) : false
end

#on_selector?(location) ⇒ true, false

Returns:

  • (true, false)


48
49
50
# File 'lib/yoda/ast/send_node.rb', line 48

def on_selector?(location)
  source_map.selector ? selector_range.include?(location) : false
end

#receiverVnode

Returns:



5
6
7
# File 'lib/yoda/ast/send_node.rb', line 5

def receiver
  children[0]
end

#selectorNameVnode

Returns:



10
11
12
# File 'lib/yoda/ast/send_node.rb', line 10

def selector
  children[1]
end

#selector_nameString

Returns:

  • (String)


15
16
17
# File 'lib/yoda/ast/send_node.rb', line 15

def selector_name
  selector.name
end

#selector_rangeParsing::Range

Returns:



74
75
76
# File 'lib/yoda/ast/send_node.rb', line 74

def selector_range
  @selector_range ||= Parsing::Range.of_ast_location(source_map.selector)
end