@Falsetru's answer is correct, but I thought I'd add this bit of code to demonstrate the various results of the proposed methods.
Two files.
hosting.rb
class Hosting def self.foo puts "__FILE__: #{__FILE__}" puts "__method__: #{__method__}" puts "caller: #{caller}" puts "caller_locations.first.path: #{caller_locations.first.path}" end end
calling.rb
require_relative 'hosting' Hosting.foo
On: ruby calling.rb output:
__FILE__: /path/to/hosting.rb __method__: foo caller: ["calling.rb:2:in `<main>'"] caller_locations.first.path: calling.rb
source share