Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Method#source_location

() -> [ ::String, ::Integer ]?
source_location → location

Returns a two-element array containing the Ruby source filename as a string and the line number integer where self is defined:

Example
def greeting = "hello"
method(:greeting).source_location # => ["test.rb", 1]

Returns nil if self is not a method defined in Ruby (i.e. defined using native code):

Example
Kernel.method(:puts).source_location # => nil
See also #receiver #source_range #parameters #super_method also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0