[Nitro] Build scripts as modules or plain scripts

George Moschovitis george.moschovitis at gmail.com
Thu Jan 4 09:28:39 EST 2007


I like this but I am not sure if there are problems with this approach. It
looks nice though...

-g.

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



-- 
http://blog.gmosx.com
http://cull.gr
http://www.joy.gr
http://nitroproject.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/nitro-general/attachments/20070104/ac040b69/attachment.html 


More information about the Nitro-general mailing list