| Class | Method |
| In: |
lib/facet/duckhunter.rb
|
| Parent: | Object |
Method::DuckHunter is a method probe. It drop decoys into methods which records the calls that are made against them. Of course it is not perfect —as a matter of course for any internal probe. There are a couple of issues related to conditionals. Since the method test for a certain condition against the decoy, how is the decoy to respond? Thus ceratin paths in the code may never get exceuted and so go unmapped. If Ruby had better conditional reflection (i.e. if ‘if’, ‘case’, ‘unless’, ‘when’, etc. were true methods) then this could be fixed by making the DuckHunter reentrant, mapping out variant true/false/nil replies. Of course the final problem is the Halting problem. It should be rare enough, but it can happen and little can be done about it (I think).
Note, the alternative to this is a program that examines, rather then executes, source code. This would circumvent the above problems, but run into difficulties with dynamic evals.
This script is provided for experimetnal purposes. On occasion it may find an intersteing use. Please inform the author if you find ways to improve.
require 'carat/duckhunter'
def amethod(x)
x + 1
end
p method(:amethod).signiture
p method(:amethod).signiture(:class)
p method(:amethod).signiture(:pretty)
produces
[["+"]]
[{"+"=>[["Fixnum"]]}]
[["+( Fixnum )"]]