M
Mauricio Fernandez
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 ()
[...]
$ method_args rational
Rational.reduce (num, den = 1)
Rational.new! (num, den = 1)
Rational#initialize (num, den)
Rational#+ (a)
[...]
$ method_args parsedate
[...]
Date#strftime (fmt = "%F")
Date#asctime ()
Date#ctime ()
DateTime._strptime (str, fmt = "%FT%T%Z")
DateTime#strftime (fmt = "%FT%T%Z")
ParseDate#parsedate (str, comp = false)
[...]
Something to play with.
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 ()
[...]
$ method_args rational
Rational.reduce (num, den = 1)
Rational.new! (num, den = 1)
Rational#initialize (num, den)
Rational#+ (a)
[...]
$ method_args parsedate
[...]
Date#strftime (fmt = "%F")
Date#asctime ()
Date#ctime ()
DateTime._strptime (str, fmt = "%FT%T%Z")
DateTime#strftime (fmt = "%FT%T%Z")
ParseDate#parsedate (str, comp = false)
[...]
Something to play with.