我-程序成长-解惑Ruby

定位方法定义的位置--source_location

2016-12-30  本文已影响2人  就叫初九吧

在写ruby代码或者rails项目的时候,借助于IDE我们能很快的找到方法定义的位置,但在使用的元编程等情况下找起来就比较麻烦了,此时可以使用source_location方法
该方法返回定义方法的源文件和行号

obj.method(:method_name).source_location

source_location → [String, Fixnum]
Returns the Ruby source filename and line number 
containing this method or nil   if this method was not defined in Ruby (i.e. native)
上一篇下一篇

猜你喜欢

热点阅读