0

I have a model with a class method.

Like:

class School < ActiveRecord::Base
   def self.mymethod
   end
   def instance_something
   end
end

How can I find the source_location of a class method in Ruby?

If I want the source location of "instance_something" I do

School.new.method(:instance_something).source_location

But I can't do that with class method.

Any help?

Tony
  • 10,088
  • 20
  • 85
  • 139

1 Answers1

0

I just did this in irb, and it works.

class Foo
  def foo
  end
  def self.bar
  end
end

f = Foo.new
m1 = f.method(:foo)
m1.source_location
 => ["(irb)", 2] 

Foo.method(:bar)
m2 = Foo.method(:bar)
m2.source_location
 => ["(irb)", 4]
Deradon
  • 1,787
  • 12
  • 17