2011-11-08 3 views
4

전 세계 네임 스페이스에서 재미 있고 (쓸데없는) 모듈과 클래스가 많은 레거시 레일 앱이 있습니다. rails c을 사용하여 필요한 파일이나 보석을 알고 싶습니다.런타임시 모듈 또는 클래스의로드 위치를 확인하는 방법은 무엇입니까?

.source_location, __line__, __file__ 및 호출자 개체가 있지만 클래스 또는 모듈의 출처를 결정하는 것과 관련이없는 것처럼 보입니다.

아이디어가 있으십니까? 감사!

사용 :

  • 루비 1.9.2
  • 들어 올립니다
  • 레일 3.1.1

답변

1

직접 클래스/모듈이를 찾을 수 없습니다 -하지만 당신은 방법을 보면가 정의 된 위치를 찾을 수 클래스/모듈에 정의 - - 프록시에 의해 클래스/모듈이 정의되는 곳이기도합니다.

Pry에서 당신은 갈 수 있습니다 : 위에서 마지막 항목에서

[3] (pry) main: 0> stat Set#initialize 
Method Information: 
-- 
Name: initialize 
Owner: Set 
Visibility: private 
Type: Unbound 
Arity: -1 
Method Signature: initialize(enum=?, &block) 
Source Location: /Users/john/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/set.rb:67 

봐.

1

더 실제 솔루션 (당신이 방법을 요구)보다 해결,하지만 난 ri doc을 사용할 것을 권장합니다. Rdoc/Ri Doc가 적절히 생성되면, doc은 소스 젬을 언급합니다.

ri ClassName#instance_method_name 
ri ClassName#class_method_name 

:

ri ClassName 

이 방법에 대한 정보를 얻을 수 :

ri -l 

가 특정 클래스 또는 모듈에 문서를 얻을 :

은 RI에 의해 알려진 모든 클래스를 나열하려면 원하는 경우 ri_for이라는 보석이있어서 ri 문서를 검사 할 수 있습니다. 런타임에는 콘솔에서 도움이 될 것입니다. IRB 세션에 대한 출력의 예 :

>> require 'ri_for' 
=> true 
>> String.desc_class 
begin RI 
String < Object 

------------------------------------------------------------------------------ 
Includes: 
Diff::LCS (from gem diff-lcs-1.1.3) 

(from gem diff-lcs-1.1.3) 
------------------------------------------------------------------------------ 
Includes Diff::LCS into String. 

------------------------------------------------------------------------------ 
(from gem rake-0.8.7) 
------------------------------------------------------------------------------ 


User defined methods to be added to String. 

------------------------------------------------------------------------------ 
Instance methods: 

ext 
pathmap 
pathmap_explode 
pathmap_partial 
pathmap_replace 

(from gem treetop-1.4.10) 
------------------------------------------------------------------------------ 
Instance methods: 

blank? 
column_of 
indent 
line_of 
tabto 
treetop_camelize 

end ri 
String 
non inherited methods: 
%, *, +, <<, <=>, ==, ===, =~, [], []=, ascii_only?, blank?, bytes, bytesize, capitalize, capitalize!, casecmp, center, chars, chomp, chomp!, chop, chop!, chr, clear, codepoints, column_of, concat, count, crypt, delete, delete!, downcase, downcase!, dump, each_byte, each_char, each_codepoint, each_line, empty?, encode, encode!, encoding, end_with?, eql?, force_encoding, getbyte, gsub, gsub!, hash, hex, include?, indent, index, insert, inspect, intern, length, line_of, lines, ljust, lstrip, lstrip!, match, next, next!, oct, ord, partition, replace, reverse, reverse!, rindex, rjust, rpartition, rstrip, rstrip!, scan, setbyte, size, slice, slice!, split, squeeze, squeeze!, start_with?, strip, strip!, sub, sub!, succ, succ!, sum, swapcase, swapcase!, tabto, to_c, to_f, to_i, to_r, to_s, to_str, to_sym, tr, tr!, tr_s, tr_s!, treetop_camelize, unpack, upcase, upcase!, upto, valid_encoding? 
non inherited class methods: 
try_convert 
=> nil 
+1

그는'ri_for' 보석의 모든 기능을 가진 Pry를 이미 사용하고 있습니다. – horseyguy

+0

멋진 것들. 치어 리더에 대해 몰랐다. –