<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: Method</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">Method</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../files/lib/carat/duckhunter_rb.html">
                lib/carat/duckhunter.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="Object.html">
                Object
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <h1><a href="Method/DuckHunter.html">DuckHunter</a></h1>
<p>
<a href="Method/DuckHunter.html">Method::DuckHunter</a> is a method probe.
It drop decoys into methods which records the calls that are made against
them. Of course it is not perfect &#8212;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
&#8216;if&#8217;, &#8216;case&#8217;, &#8216;unless&#8217;,
&#8216;when&#8217;, etc. were true methods) then this could be fixed by
making the <a href="Method/DuckHunter.html">DuckHunter</a> 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).
</p>
<p>
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.
</p>
<p>
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.
</p>
<h2>Synopsis</h2>
<pre>
  require 'carat/duckhunter'

  def amethod(x)
    x + 1
  end

  p method(:amethod).signiture
  p method(:amethod).signiture(:class)
  p method(:amethod).signiture(:pretty)
</pre>
<p>
produces
</p>
<pre>
  [[&quot;+&quot;]]
  [{&quot;+&quot;=&gt;[[&quot;Fixnum&quot;]]}]
  [[&quot;+( Fixnum )&quot;]]
</pre>
<h2>Authors(s)</h2>
<ul>
<li>Thomas Sawyer

</li>
</ul>
<h2>Legal</h2>
<p>
Ruby License Copyright &#169;2005 Thomas Sawyer
</p>
<h2>History</h2>
<ul>
<li>2005.04.12 Passed basic tests.

</li>
</ul>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000156">migration</a>&nbsp;&nbsp;
      <a href="#M000157">signature</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">

    <div id="class-list">
      <h3 class="section-bar">Classes and Modules</h3>

      Class <a href="Method/DuckHunter.html" class="link">Method::DuckHunter</a><br />

    </div>




      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000157" class="method-detail">
        <a name="M000157"></a>

        <div class="method-heading">
          <a href="#M000157" class="method-signature">
          <span class="method-name">signature</span><span class="method-args">(detail=nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Outputs signiture information.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000157-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000157-source">
<pre>
<span class="ruby-comment cmt"># File lib/carat/duckhunter.rb, line 136</span>
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">signature</span>(<span class="ruby-identifier">detail</span>=<span class="ruby-keyword kw">nil</span>)
    <span class="ruby-identifier">ds</span> = []
    <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">detail</span>
    <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:complete</span>, <span class="ruby-identifier">:all</span>, <span class="ruby-identifier">:full</span>
      <span class="ruby-identifier">ds</span> = <span class="ruby-identifier">migration</span>
    <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:class</span>, <span class="ruby-identifier">:with_class</span>
      <span class="ruby-identifier">migration</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">dh</span><span class="ruby-operator">|</span> <span class="ruby-identifier">ds</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">dh</span>.<span class="ruby-identifier">ducks</span> }
    <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:pp</span>, <span class="ruby-identifier">:pretty</span>, <span class="ruby-identifier">:prettyprint</span>, <span class="ruby-identifier">:pretty_print</span>
      <span class="ruby-identifier">migration</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">dh</span><span class="ruby-operator">|</span>
        <span class="ruby-identifier">responders</span> = []
        <span class="ruby-identifier">dh</span>.<span class="ruby-identifier">ducks</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">responder</span>, <span class="ruby-identifier">argss</span><span class="ruby-operator">|</span>
          <span class="ruby-identifier">argss</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">args</span><span class="ruby-operator">|</span> <span class="ruby-identifier">responders</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;#{responder}( #{args.join(',')} )&quot;</span> }
        <span class="ruby-keyword kw">end</span>
        <span class="ruby-identifier">ds</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">responders</span>
      <span class="ruby-keyword kw">end</span>
    <span class="ruby-keyword kw">else</span>
      <span class="ruby-identifier">migration</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">dh</span><span class="ruby-operator">|</span> <span class="ruby-identifier">ds</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">dh</span>.<span class="ruby-identifier">ducks</span>.<span class="ruby-identifier">keys</span> }
    <span class="ruby-keyword kw">end</span>
    <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">ds</span>
  <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Private Instance methods</h3>

      <div id="method-M000156" class="method-detail">
        <a name="M000156"></a>

        <div class="method-heading">
          <a href="#M000156" class="method-signature">
          <span class="method-name">migration</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Outputs migration information.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000156-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000156-source">
<pre>
<span class="ruby-comment cmt"># File lib/carat/duckhunter.rb, line 122</span>
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">migration</span>
    <span class="ruby-identifier">parameters</span> = []; <span class="ruby-identifier">argc</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">arity</span>
    <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">argc</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
      <span class="ruby-identifier">argc</span>.<span class="ruby-identifier">times</span> { <span class="ruby-identifier">parameters</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">DuckHunter</span>.<span class="ruby-identifier">new</span> }
      <span class="ruby-constant">DuckHunter</span>.<span class="ruby-identifier">duckcall</span> { <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">call</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">parameters</span>) }
    <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">argc</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span>
      <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;(NYI) method takes unlimited arguments&quot;</span>
    <span class="ruby-keyword kw">end</span>
    <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">parameters</span>
  <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>