From: Ezra Zygmuntowicz Date: 2006-09-12T06:53:26+09:00 Subject: Re: Getting argument names and default values: doable (if hackish) On Sep 11, 2006, at 11:10 AM, Mauricio Fernandez wrote: > I've written some code to get the argument names and their default > values (if > any) as methods are defined; it can be found at > http://eigenclass.org/hiki.rb?method+arguments+via+introspection > > It uses some tricky introspection to do it at runtime. That is, it > does *not* > operate like e.g. rdoc, by parsing the source code. Instead, it > actually > #require()s the code, so it will not be confused by your meta- > programming, > normally. > > I've made a simple script that uses that to list the public methods > that will > be defined when you require a given .rb file. Its output looks like > this: > > $ method_args benchmark > Benchmark#benchmark (caption = "", label_width = nil, fmtstr = nil, > *labels) > Benchmark#bm (label_width = 0, *labels) > Benchmark#bmbm (width = 0) > Benchmark#measure (label = "") > Benchmark#realtime () > [...] Hey Mauricio- This is super cool stuff. I'm playing with it now using the version from your site with the patch applied and it spits out all the method names but just puts ... instead of the arguments. It does this for anything i give it from the stdlib or my own code. ez engine_yard $ method_args.rb benchmark # Benchmark#benchmark (...) Benchmark#bm (...) Benchmark#bmbm (...) Benchmark#measure (...) Benchmark#realtime (...) Benchmark::Job#initialize (...) Benchmark::Job#item (...) Benchmark::Job#report (...) I'm on OSX Tiger latest with my own compiled ruby1.8.4. Does this require 1.8.5 or am I doing something stupid? Cheers- -Ezra