Method: Sourcify::Proc::Stubs#source_location

Defined in:
lib/sourcify/proc.rb

#source_location(get_original = true) ⇒ Object

Returns the ruby source filename and line number containing this proc.

# /tmp/test.rb
x = lambda { 1 }
x.source_location # >> ["/tmp/test.rb", 2]

When proc is not defined in ruby (i.e. native), or when the proc is created using Method#to_proc or Symbol#to_proc, nil is returned.

class AA
  class << self
    def m1; 1; end
    def m2(&block); block; end
  end
end

AA.method(:m1).to_proc.source_location # >> nil
AA.m2(&:m1).source_location            # >> nil

For 1.9.2, the proc obtained using Method#to_proc by default yields info pointing to where the method is located. Sourcify respects this builtin implementation and assumes you usually want it. It is possible to get info that is consistent with all other rubies by passing in get_original as false:

# /tmp/test.rb
class AA
  def m; 1; end
end

x = AA.new.method(:m).to_proc
x.source_location        # >> ["/tmp/test.rb", 2]
x.source_location(false) # >> nil


57
58
59
# File 'lib/sourcify/proc.rb', line 57

def source_location(get_original = true)
  # NOTE: this is a stub for the actual one in Methods::SourceLocation
end