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 = Util::AddedMethods.find(
:name => 'method_name',
:class => 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 = 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.html>
[2] <http://rubyforge.org/projects/prometheus/>
[3] <http://prometheus.khi.uni-koeln.de/rubygems/>
cheers
jens
···
--
Jens Wille, Dipl.-Bibl. (FH)
prometheus - Das verteilte digitale Bildarchiv für Forschung & Lehre
Kunsthistorisches Institut der Universität zu Köln
Albertus-Magnus-Platz, D-50923 Köln
Tel.: +49 (0)221 470-6668, E-Mail: jens.wille@uni-koeln.de
http://www.prometheus-bildarchiv.de/