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: MonkeyPatchRecordBuilder, RecordBuilder

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

Methods included from Send::TargetDetection

#conversion_target?, #dynamic_analysis_target?

Instance Method Details

#and_return?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/transpec/syntax/mixin/useless_and_return.rb', line 31

def and_return?
  and_return_node
end

#and_return_nodeObject



35
36
37
38
39
40
41
42
# File 'lib/transpec/syntax/mixin/useless_and_return.rb', line 35

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

Returns:

  • (Boolean)


26
27
28
29
# File 'lib/transpec/syntax/mixin/useless_and_return.rb', line 26

def and_return_with_block?
  block_node = Util.block_node_taken_by_method(and_return_node)
  block_node
end

#remove_useless_and_return!Object



14
15
16
17
18
# File 'lib/transpec/syntax/mixin/useless_and_return.rb', line 14

def remove_useless_and_return!
  return unless useless_and_return?
  remove(and_return_range)
  true
end

#useless_and_return?Boolean

Returns:

  • (Boolean)


20
21
22
23
24
# File 'lib/transpec/syntax/mixin/useless_and_return.rb', line 20

def useless_and_return?
  return false unless and_return?
  arg_node = and_return_node.children[2]
  arg_node.nil?
end