I like this but I am not sure if there are problems with this approach. It looks nice though...<br><br>-g.<br><br><div><span class="gmail_quote">On 1/4/07, <b class="gmail_sendername"><a href="mailto:transfire@gmail.com">transfire@gmail.com
</a></b> &lt;<a href="mailto:transfire@gmail.com">transfire@gmail.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I&#39;m cross posting this b/c it has to do with Ratchets:
<br><br>I&#39;m having a little debate with myself. On my current project I have a<br>bunch of little reusable task scripts that a command line tool runs.<br>The scripts are written as the top-level (although I actually simulate
<br>the top-level when running them). So for example a script would just be<br>something like:<br><br>&nbsp;&nbsp;# example.rb<br><br>&nbsp;&nbsp;def example<br>&nbsp;&nbsp;&nbsp;&nbsp;puts &quot;This is an example!&quot;<br>&nbsp;&nbsp;end<br><br>Then on the command line I would do:
<br><br>&nbsp;&nbsp;% mytool example<br>&nbsp;&nbsp;This is an example!<br><br>That&#39;s all well and good, but many of the scripts have generally useful<br>routines and I would like them to be accessible by other programs too,<br>not just my command line tool. So I thoght maybe it would be better if
<br>a module were required to wrap the defs.<br><br>&nbsp;&nbsp;# another.rb<br><br>&nbsp;&nbsp;module MyToolAnother<br><br>&nbsp;&nbsp;&nbsp;&nbsp;def another<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts &quot;This is another!&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;end<br><br>&nbsp;&nbsp;end<br><br>That works, of course, but it adds an additonal layer of essentially
<br>redundant code, which IMHO is ugly.<br><br>Then I got to thinking. Why don&#39;t we write resuable lib in this fashion<br>anyway and just create our own containers on the fly when loading them?<br><br>&nbsp;&nbsp;MyToolExample = load_as_module &quot;
example.rb&quot;<br><br>What intersting about that is then we could determine in what capacity<br>it is to be used. For example:<br><br>&nbsp;&nbsp;# adds module_function<br>&nbsp;&nbsp;MyToolExample = load_as_function_module &quot;example.rb
&quot;<br><br>&nbsp;&nbsp;# adds self extend<br>&nbsp;&nbsp;MyToolExample = load_as_self_extended_module &quot;example.rb&quot;<br><br>Or even<br><br>&nbsp;&nbsp;MyToolExample = load_as_class &quot;example.rb&quot;<br><br>We could even have include and extend take a lib path.
<br><br>&nbsp;&nbsp;include &quot;example.rb&quot;<br><br>Of course this effectively puts encapsulation, at least at the top<br>level, on a per-file basis. But in many respects that seems kind of<br>nice. It increases flexability and reduces configuration complexity.
<br><br>So what do your think? Is this technique worth promoting? Or am I being<br>silly and should just wrap all my scripts in modules?<br><br>T.<br><br>_______________________________________________<br>Nitro-general mailing list
<br><a href="mailto:Nitro-general@rubyforge.org">Nitro-general@rubyforge.org</a><br><a href="http://rubyforge.org/mailman/listinfo/nitro-general">http://rubyforge.org/mailman/listinfo/nitro-general</a><br></blockquote></div>
<br><br clear="all"><br>-- <br><a href="http://blog.gmosx.com">http://blog.gmosx.com</a><br><a href="http://cull.gr">http://cull.gr</a><br><a href="http://www.joy.gr">http://www.joy.gr</a><br><a href="http://nitroproject.org">
http://nitroproject.org</a>