Class: Test::Unit::Assertions::RubyReflector::CallMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/assert2/rubynode_reflector.rb

Instance Method Summary collapse

Instance Method Details

#bracket_argsObject



709
710
711
712
713
# File 'lib/assert2/rubynode_reflector.rb', line 709

def bracket_args
  return false unless @mid == '[]'
  @expression << '[' + @ref.args_(@node) + ']'
  return true
end

#caller(ref, node) ⇒ Object



752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
# File 'lib/assert2/rubynode_reflector.rb', line 752

def caller(ref, node)
  @ref, @node = ref, node
  @expression = ''
  @recv    = @node[:recv]

  if @recv.first == :block_pass
    @expression << @ref.recv_(@node)
    operator_and_arguments
  else
    nest_me = @recv.first == :call && @ref.we_b_op(@recv.last)

    exp = if @recv.first == :array
      @ref.nest_if(true, '[ ', ' ]'){ @ref.recv_(node) }
    else
      exp2 = @ref.nest_if(nest_me, '( ', ' )'){ @ref.recv_(node) }
      @ref.eval_intermediate(exp2)  if nest_me
      exp2
    end

    @expression << exp
    operator_and_arguments
  end
  return @expression
end

#insert_method_callObject



715
716
717
718
719
720
# File 'lib/assert2/rubynode_reflector.rb', line 715

def insert_method_call
  @expression << '.'
  @expression << @mid
  @expression << '(' + @ref.args_(@node) + ')'
  @ref.eval_intermediate(@expression) if @methodic
end

#nest_argsObject



739
740
741
742
743
744
745
746
747
748
749
750
# File 'lib/assert2/rubynode_reflector.rb', line 739

def nest_args
  return unless @args = @node[:args]
  
  nest_me = @args.first == :array && 
            @args.last.length == 1 &&
            (call = @args.last.first).first == :call &&
            @ref.we_b_op(call.last)

  exp = @ref.nest_if(nest_me, '( ', ' )'){ @ref.args_(@node) }
  @ref.eval_intermediate(exp) if nest_me
  @expression << exp
end

#operator_and_argumentsObject



722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
# File 'lib/assert2/rubynode_reflector.rb', line 722

def operator_and_arguments
  @mid = @ref.mid_(@node)

  unless bracket_args
    @methodic = @mid =~ /[a-z]/i

    if @methodic
      insert_method_call
    else
      @expression << ' '
      @expression << @mid
      @expression << ' '
      nest_args
    end
  end
end