From: Dean Wampler Date: 2008-07-28T03:00:57+09:00 Subject: Re: Is there a simple way to find a method definition? ------=_Part_8640_27231434.1217181674913 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Thanks. I'll give it a try.dean On Sun, Jul 27, 2008 at 12:04 PM, Jens Wille wrote= : > hi dean! > > Dean Wampler [2008-07-27 16:50]: > > Does anyone know of a programmatic way to find the definition? > this is exactly what you can do with AddedMethods [1]: > > require 'rubygems' > require 'nuggets/util/added_methods/init' > > require 'your/library/or/whatever' > > matches =3D Util::AddedMethods.find( > :name =3D> 'method_name', > :class =3D> YourClass # optional > ) > > # get the class(es) where matching method(s) were defined > matches.each { |am| puts am[:class] # or am.klass } > > # assume the first one is the one we're looking for > am =3D matches.first > > # is it a singleton method? > puts am.singleton > > # where exactly has it been defined? > puts "#{am.file}, line #{am.line}" > > # now get its source > puts am # implies #to_s, you can also call #extract_source directly > > does that help in any way? if you trip over any quirks or even bugs, > or if you have any suggestions, please let me know. as i said > earlier in this thread, you can get ruby-nuggets, which this library > is a part of, from rubyforge [2] or from our own gem server [3]. > > [1] > < > http://prometheus.rubyforge.org/ruby-nuggets/classes/Util/AddedMethods.ht= ml > > > [2] > [3] > > cheers > jens > > -- > Jens Wille, Dipl.-Bibl. (FH) > prometheus - Das verteilte digitale Bildarchiv f=FCr Forschung & Lehre > Kunsthistorisches Institut der Universit=E4t zu K=F6ln > Albertus-Magnus-Platz, D-50923 K=F6ln > Tel.: +49 (0)221 470-6668, E-Mail: jens.wille@uni-koeln.de > http://www.prometheus-bildarchiv.de/ > > --=20 Dean Wampler http://www.objectmentor.com http://www.aspectprogramming.com http://aquarium.rubyforge.org http://www.contract4j.org ------=_Part_8640_27231434.1217181674913--