Class: Method

Inherits:
Object
  • Object
show all
Defined in:
lib/bently/core_ext/method.rb

Instance Method Summary collapse

Instance Method Details

#source_locationArray

Return the source location of a method for Ruby 1.8.

Returns:

  • (Array)

    A two element array. First element is the file, second element is the line in the file where the method definition is found.



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/bently/core_ext/method.rb', line 41

def source_location
  if @file.nil?
    args =[*(1..(arity<-1 ? -arity-1 : arity ))]

    set_trace_func method(:trace_func).to_proc
    call(*args) rescue nil
    set_trace_func nil
    @file = File.expand_path(@file) if @file && File.exist?(File.expand_path(@file))
  end
  [@file, @line] if @file
end