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
#comments_by_vnode, #positionally_nearest_comment, #positionally_nearest_commenting_node
#location, #positionally_include?, #positionally_nearest_child, #range, #source_map
#all_nodes_lazy, #associate_comments, #comments, #wrapping?
#query, #query_all, #query_ancestor, #query_ancestors
#calc_current_location_method, #including_method, #method?
#calc_current_location_namespace, #full_name, #namespace, #namespace?, #namespace_path, #root?
Instance Method Details
#arguments ⇒ Array<Vnode>
20
21
22
|
# File 'lib/yoda/ast/send_node.rb', line 20
def arguments
children.slice(2..-1)
end
|
#block_pass_argument ⇒ Object
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
|
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_arguments ⇒ Array<Vnode>
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
43
44
45
|
# File 'lib/yoda/ast/send_node.rb', line 43
def implicit_receiver?
receiver.empty?
end
|
#keyword_argument ⇒ Object
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
|
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
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
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
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
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
|
#receiver ⇒ Vnode
5
6
7
|
# File 'lib/yoda/ast/send_node.rb', line 5
def receiver
children[0]
end
|
10
11
12
|
# File 'lib/yoda/ast/send_node.rb', line 10
def selector
children[1]
end
|
#selector_name ⇒ String
15
16
17
|
# File 'lib/yoda/ast/send_node.rb', line 15
def selector_name
selector.name
end
|
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
|