2013-04-11 47 views
0

我有一个类方法的模型。需要找到类方法的source_location

像:

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

如何找到在Ruby中类方法的源位置?

如果我想“instance_something”的源位置我

School.new.method(:instance_something).source_location 

但我不能做到这一点与类的方法。

任何帮助?

回答

0

我刚刚在irb中做了这个,它工作。

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]