Module: Transpec::Syntax::Mixin::UselessAndReturn
- Extended by:
- ActiveSupport::Concern
- Includes:
- Send
- Included in:
- MessagingHost
- Defined in:
- lib/transpec/syntax/mixin/useless_and_return.rb
Defined Under Namespace
Classes: MonkeyPatchUselessAndReturnRecord, UselessAndReturnRecord
Instance Method Summary
collapse
Methods included from Send
#arg_node, #arg_nodes, #arg_range, #args_range, #method_name, #parentheses_range, #range_after_arg, #range_in_between_receiver_and_selector, #range_in_between_selector_and_arg, #receiver_node, #receiver_range, #selector_range
Instance Method Details
#and_return? ⇒ Boolean
33
34
35
|
# File 'lib/transpec/syntax/mixin/useless_and_return.rb', line 33
def and_return?
!and_return_node.nil?
end
|
#and_return_node ⇒ Object
37
38
39
40
41
42
43
44
|
# File 'lib/transpec/syntax/mixin/useless_and_return.rb', line 37
def and_return_node
return @and_return_node if instance_variable_defined?(:@and_return_node)
@and_return_node = Util.each_backward_chained_node(node) do |chained_node|
method_name = chained_node.children[1]
break chained_node if method_name == :and_return
end
end
|
#and_return_with_block? ⇒ Boolean
28
29
30
31
|
# File 'lib/transpec/syntax/mixin/useless_and_return.rb', line 28
def and_return_with_block?
block_node = Util.block_node_taken_by_method(and_return_node)
!block_node.nil?
end
|
#remove_useless_and_return! ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/transpec/syntax/mixin/useless_and_return.rb', line 14
def remove_useless_and_return!
return unless useless_and_return?
map = and_return_node.loc
and_return_range = map.dot.join(map.expression.end)
remove(and_return_range)
true
end
|
#useless_and_return? ⇒ Boolean
22
23
24
25
26
|
# File 'lib/transpec/syntax/mixin/useless_and_return.rb', line 22
def useless_and_return?
return false unless and_return?
arg_node = and_return_node.children[2]
arg_node.nil?
end
|