Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
UnboundMethod#source_location
() -> [ ::String, ::Integer ]?
source_location → location
proc.c
View on GitHub ↗
VALUE
rb_method_location(VALUE method)
{
return method_def_location(rb_method_def(method));
}
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