[#316551] "ensure" hiding actual error — Nit Khair <sentinel.2001@...>

In my main program I have a "begin ensure end".

19 messages 2008/10/01
[#316566] Re: "ensure" hiding actual error — "Robert Klemme" <shortcutter@...> 2008/10/01

2008/10/1 Nit Khair <sentinel.2001@gmx.com>:

[#316570] Re: "ensure" hiding actual error — Nit Khair <sentinel.2001@...> 2008/10/01

Robert Klemme wrote:

[#316579] Re: "ensure" hiding actual error — "Robert Klemme" <shortcutter@...> 2008/10/01

2008/10/1 Nit Khair <sentinel.2001@gmx.com>:

[#316583] Re: "ensure" hiding actual error — Nit Khair <sentinel.2001@...> 2008/10/01

Robert Klemme wrote:

[#316585] Re: "ensure" hiding actual error — "Thomas B." <tpreal@...> 2008/10/01

Nit Khair wrote:

[#316589] Re: "ensure" hiding actual error — "Robert Klemme" <shortcutter@...> 2008/10/01

2008/10/1 Thomas B. <tpreal@gmail.com>:

[#316617] Ordered hash hack for < ruby 1.9? — Ben Johnson <bjohnson@...>

I am having an issue testing my code because hashes don't have a

22 messages 2008/10/01
[#316620] Re: Ordered hash hack for < ruby 1.9? — "Patrick Doyle" <wpdster@...> 2008/10/01

Why not iterate over myhash.keys.sort instead of just myhash.keys?

[#316704] Problem extending (adding methods) to class — Nit Khair <sentinel.2001@...>

I am trying to extend a class developed by someone else (its from the

24 messages 2008/10/02
[#316707] Re: Problem extending (adding methods) to class — Nit Khair <sentinel.2001@...> 2008/10/02

Nit Khair wrote:

[#316723] Is Assignment in a Conditional an Idiom? — worthee@...

Hi

19 messages 2008/10/02

[#316839] class << self — "Patrick Doyle" <wpdster@...>

Sorry if this is a FAQ, but I was just looking at some Ruby code and

14 messages 2008/10/03

[#316847] Making/Compiling Gems on Windows with MinGW — Cayce Balara <house@...>

Whenever I try to install a gem that doesn't have a precompiled binary

11 messages 2008/10/03

[#316907] stream closed (IOError) — "Eric Will" <rakaur@...>

This code:

17 messages 2008/10/05
[#316910] Re: stream closed (IOError) — Yukihiro Matsumoto <matz@...> 2008/10/05

Hi,

[#316920] Re: stream closed (IOError) — "Eric Will" <rakaur@...> 2008/10/05

Line 231 is the @socket.close line. Nothing gets done to the socket

[#316925] Re: stream closed (IOError) — Yukihiro Matsumoto <matz@...> 2008/10/05

Hi,

[#316926] Re: stream closed (IOError) — "Eric Will" <rakaur@...> 2008/10/05

On Sun, Oct 5, 2008 at 11:46 AM, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:

[#316927] Re: stream closed (IOError) — Iki Baz Castillo <ibc@...> 2008/10/05

El Domingo, 5 de Octubre de 2008, Eric Will escribi=F3:

[#316968] Ruby lacks atfork : The evil that lives in fork... — John Carter <john.carter@...>

Consider this simple usage of Thread and Process....

12 messages 2008/10/06

[#316978] Concurent (using threads) slower than sequential -doubt — Carlos Ortega <caof2005@...>

Hi Folks.

10 messages 2008/10/06

[#316988] Problem with comparing huge amount of strings — Jan Fischer <janfischer@...>

Hello together,

11 messages 2008/10/06

[#317122] Demand that Obama release his college records! Where is the media? — Micky <guuwwe@...>

Why is it important to see Obama's college records? Because the media

11 messages 2008/10/07

[#317126] Ruby with Oracle forward slash error — Sam Sang <younoeme@...>

Hi,

12 messages 2008/10/07

[#317127] Looking for more Ruby-like way to create an array — Steve Nicholson <ssteve@...>

I'm creating an array that is the result of the members of another array

11 messages 2008/10/07

[#317326] Thread: super should be first line or last line? — "christoforever@..." <christoforever@...>

While playing around with ruby threads I noticed that if you dont call

11 messages 2008/10/10

[#317337] Modular Arithmetic (#179) — Matthew Moss <matt@...>

-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D=

15 messages 2008/10/10

[#317395] Automatic ClassLoader (to eliminate 'require') — Alexey Petrushin <axyd80@...>

Hello!

17 messages 2008/10/11
[#317397] Re: Automatic ClassLoader (to eliminate 'require') — Erik Veenstra <erikveen@...> 2008/10/11

module AutoRequire

[#317402] Re: Automatic ClassLoader (to eliminate 'require') — Alexey Petrushin <axyd80@...> 2008/10/11

Thanks! It works! :)

[#317403] Re: Automatic ClassLoader (to eliminate 'require') — "Thomas B." <tpreal@...> 2008/10/11

Alexey Petrushin wrote:

[#317422] Sample for Metaprogramming — relzne@...

Hi.

13 messages 2008/10/11

[#317452] Updating Ruby 1.8.6 to 1.8.6-p287 in Debian 4 — The Neurochild <neurochild@...>

Hi

21 messages 2008/10/12

[#317502] Sorting help — Binh Ly <binh@...>

Hello All,

19 messages 2008/10/12

[#317601] Using DBI and MySQL gems — Owein Herrmann <oherrmann@...>

Quick question:

14 messages 2008/10/13

[#317758] Big endian convention in Ruby — Zangief Ief <z4n9ief@...>

Hello,

18 messages 2008/10/16
[#317767] Re: Big endian convention in Ruby — Robert Klemme <shortcutter@...> 2008/10/16

On 16.10.2008 10:26, Zangief Ief wrote:

[#317772] Re: Big endian convention in Ruby — Zangief Ief <z4n9ief@...> 2008/10/16

Thanks you for you answer.

[#317800] Re: Big endian convention in Ruby — Brian Candler <b.candler@...> 2008/10/16

Zangief Ief wrote:

[#317820] Re: Big endian convention in Ruby — Robert Klemme <shortcutter@...> 2008/10/16

On 16.10.2008 15:25, Brian Candler wrote:

[#317936] Re: Big endian convention in Ruby — Zangief Ief <z4n9ief@...> 2008/10/17

Thank you all for your help.

[#317759] How to go from a ruby script to a working website? — Ralph Wood <esmero@...>

As you've probably guessed by the title, total newbie here.

12 messages 2008/10/16

[#317769] A Ruby block question — David Trasbo <davidtrasbo@...>

I am in need of making a method that accepts a block. It basicly needs

23 messages 2008/10/16
[#317770] Re: A Ruby block question — Stefano Crocco <stefano.crocco@...> 2008/10/16

Alle Thursday 16 October 2008, David Trasbo ha scritto:

[#317773] Re: A Ruby block question — David Trasbo <davidtrasbo@...> 2008/10/16

Stefano Crocco wrote:

[#317779] Re: A Ruby block question — Stefano Crocco <stefano.crocco@...> 2008/10/16

Alle Thursday 16 October 2008, David Trasbo ha scritto:

[#317780] Re: A Ruby block question — David Trasbo <davidtrasbo@...> 2008/10/16

Stefano Crocco wrote:

[#317776] I found way to protect Source Code! :) — Alexey Petrushin <axyd80@...>

Hello!

34 messages 2008/10/16
[#317859] Re: I found way to protect Source Code! :) — Ade Inovica <adrian.teasdale@...> 2008/10/16

Interesting solution. May I also suggest that you try

[#317869] Re: I found way to protect Source Code! :) — Mike Gold <mike.gold.4433@...> 2008/10/16

Ade Inovica wrote:

[#317886] Re: I found way to protect Source Code! :) — Sasha Bee <rubyman77@...> 2008/10/17

Mike Gold wrote:

[#317956] Re: I found way to protect Source Code! :) — "ara.t.howard" <ara.t.howard@...> 2008/10/17

[#317878] instance counter — Pierre Lebrun <anthonylebrun@...>

Please forgive the trite nature of this question, I'm new to ruby and OO

21 messages 2008/10/17
[#317880] Re: instance counter — Tommy Nordgren <tommy.nordgren@...> 2008/10/17

[#317883] Re: instance counter — Mike Gold <mike.gold.4433@...> 2008/10/17

Tommy Nordgren wrote:

[#317903] Re: instance counter — Robert Klemme <shortcutter@...> 2008/10/17

On 17.10.2008 07:19, Mike Gold wrote:

[#317938] Error Exception if script doesn't run — jackster the jackle <johnsheahan@...>

I need to know if my script fails to run for any reason and capture the

20 messages 2008/10/17
[#317941] Re: Error Exception if script doesn't run — Brian Candler <b.candler@...> 2008/10/17

jackster the jackle wrote:

[#317967] Re: Error Exception if script doesn't run — jackster the jackle <johnsheahan@...> 2008/10/17

I notice that any shell commands that I have in the script that fail do

[#317972] Re: Error Exception if script doesn't run — Joel VanderWerf <vjoel@...> 2008/10/17

jackster the jackle wrote:

[#317974] Re: Error Exception if script doesn't run — jackster the jackle <johnsheahan@...> 2008/10/17

It seems to work but not for this command, perhaps since scp gets

[#317979] Re: Error Exception if script doesn't run — Tim Hunter <TimHunter@...> 2008/10/18

jackster the jackle wrote:

[#317992] Re: Error Exception if script doesn't run — jackster the jackle <johnsheahan@...> 2008/10/18

Tim Hunter wrote:

[#317966] Counting — Tom Clarke <thomas.clarke08@...>

How would i go about making Ruby count to say 1000 usin only multiples

18 messages 2008/10/17

[#318286] Trollop 1.10 released — William Morgan <wmorgan-ruby-talk@...>

Trollop version 1.10 has been released!

12 messages 2008/10/22

[#318309] Is there a method_eval or similar thing ? — Nit Khair <sentinel.2001@...>

I have a method called askyesno which takes a string and returns whether

13 messages 2008/10/22

[#318323] What exactly does "rubyish" or "ruby way" mean? — Nit Khair <sentinel.2001@...>

Over the last month I have been reading a lot of blogs, searching, going

12 messages 2008/10/22

[#318509] How to tell if two paths point to the same file? — Kenneth McDonald <kenneth.m.mcdonald@...>

I've tried using File.expand_path to normalize path names, but this

12 messages 2008/10/24

[#318523] RubyMacros 0.1.0 Released — "Caleb Clausen" <vikkous@...>

RubyMacros is a lisp-like macro pre-processor for Ruby. More than just a

15 messages 2008/10/24

[#318552] Join all text files in a folder, with a single line of Ruby code — luisbebop <luisbebop@...>

I did a single line of code in Ruby, which joins all text files in a

26 messages 2008/10/25
[#318556] Re: Join all text files in a folder, with a single line of Ruby code — "William James" <w_a_x_man@...> 2008/10/25

luisbebop wrote:

[#318574] Re: Join all text files in a folder, with a single line of Ruby code — Joel VanderWerf <vjoel@...> 2008/10/25

William James wrote:

[#318607] Re: Join all text files in a folder, with a single line of Ruby code — Nobuyoshi Nakada <nobu@...> 2008/10/26

Hi,

[#318622] Re: Join all text files in a folder, with a single line of Ruby code — Joel VanderWerf <vjoel@...> 2008/10/26

Nobuyoshi Nakada wrote:

[#318640] Re: Join all text files in a folder, with a single line of Ruby code — luisbebop <luisbebop@...> 2008/10/27

> ruby -pe'1' *

[#318641] Re: Join all text files in a folder, with a single line of Ruby code — Joel VanderWerf <vjoel@...> 2008/10/27

luisbebop wrote:

[#318601] Hash.merge_add! extension - how does this code look? — "Greg Hauptmann" <greg.hauptmann.ruby@...>

Hi,

18 messages 2008/10/26
[#318632] Re: Hash.merge_add! extension - how does this code look? — Stefan Rusterholz <apeiros@...> 2008/10/26

Greg Hauptmann wrote:

[#318644] Re: Hash.merge_add! extension - how does this code look? — "Greg Hauptmann" <greg.hauptmann.ruby@...> 2008/10/27

thanks for highlighting this! Is the quickest way to normalise to Array via

[#318655] Re: Hash.merge_add! extension - how does this code look? — Stefan Rusterholz <apeiros@...> 2008/10/27

Greg Hauptmann wrote:

[#318656] Re: Hash.merge_add! extension - how does this code look? — "Greg Hauptmann" <greg.hauptmann.ruby@...> 2008/10/27

I just noticed the code suggested might have a problem when the

[#318721] automatic code conversion from Ruby to C ? — "Axel Etzold" <AEtzold@...>

Dear all,

16 messages 2008/10/27

[#318888] project manager panel in SciTE — Li Chen <chen_li3@...>

Hi all,

14 messages 2008/10/29

[#318896] RubyGems 1.3.1 — Eric Hodel <drbrain@...7.net>

= Announce: RubyGems Release 1.3.1

13 messages 2008/10/29

[#318970] Roguelike project? — Tim Mcd <tmcdowell@...>

Anyone interested in a Roguelike game written in Ruby/Ncurses project?

41 messages 2008/10/30
[#318976] Re: Roguelike project? — Matthew Moss <matt@...> 2008/10/30

> Anyone interested in a Roguelike game written in Ruby/Ncurses project?

[#319050] Re: Roguelike project? — "Michael Fellinger" <m.fellinger@...> 2008/10/31

On Fri, Oct 31, 2008 at 3:42 AM, Matthew Moss <matt@moss.name> wrote:

[#319052] Re: Roguelike project? — Nit Khair <sentinel.2001@...> 2008/10/31

Michael Fellinger wrote:

[#319056] Re: Roguelike project? — "Michael Fellinger" <m.fellinger@...> 2008/10/31

On Sat, Nov 1, 2008 at 1:46 AM, Nit Khair <sentinel.2001@gmx.com> wrote:

[#319287] Re: Roguelike project? — Nit Khair <sentinel.2001@...> 2008/11/03

Michael Fellinger wrote:

[#319393] Re: Roguelike project? — Nit Khair <sentinel.2001@...> 2008/11/04

Nit Khair wrote:

[#319422] Re: Roguelike project? — Nit Khair <sentinel.2001@...> 2008/11/04

Nit Khair wrote:

[#319021] XML builder performance — Xin Zheng <crazygecko@...>

Hi all,

13 messages 2008/10/31

[#319055] How to access to local variables in enclosing scopes? — Yuh-Ruey Chen <maian330@...>

I'm familiar with other popular scripting languages (JS and Python),

34 messages 2008/10/31

[#319094] FFI 0.1.1 (Foreign Function Interface) for Ruby 1.8.6/7 and 1.9 — Charles Oliver Nutter <charles.nutter@...>

The JRuby team is proud to announce the release of FFI for Ruby 1.8.6/7

62 messages 2008/10/31
[#319099] Re: [ANN] FFI 0.1.1 (Foreign Function Interface) for Ruby 1.8.6/7 and 1.9 — Thomas Hurst <tom.hurst@...> 2008/11/01

* Charles Oliver Nutter (charles.nutter@sun.com) wrote:

[#319101] Re: [ANN] FFI 0.1.1 (Foreign Function Interface) for Ruby 1.8.6/7 and 1.9 — Charles Oliver Nutter <charles.nutter@...> 2008/11/01

Thomas Hurst wrote:

[#319113] Re: [ANN] FFI 0.1.1 (Foreign Function Interface) for Ruby 1.8.6/7 and 1.9 — Charles Oliver Nutter <charles.nutter@...> 2008/11/01

Charles Oliver Nutter wrote:

[#319238] Re: [ANN] FFI 0.1.1 (Foreign Function Interface) for Ruby 1.8.6/7 and 1.9 — Sylvain Joyeux <sylvain.joyeux@...> 2008/11/03

On Sat, Nov 01, 2008 at 08:16:39AM +0900, Charles Oliver Nutter wrote:

[#319240] Re: [ANN] FFI 0.1.1 (Foreign Function Interface) for Ruby 1.8.6/7 and 1.9 — Charles Oliver Nutter <charles.nutter@...> 2008/11/03

Sylvain Joyeux wrote:

[#319390] Re: [ANN] FFI 0.1.1 (Foreign Function Interface) for Ruby 1.8.6/7 and 1.9 — Ken Bloom <kbloom@...> 2008/11/04

On Fri, 31 Oct 2008 18:16:39 -0500, Charles Oliver Nutter wrote:

[#319391] Re: [ANN] FFI 0.1.1 (Foreign Function Interface) for Ruby 1.8.6/7 and 1.9 — "Sean O'Halpin" <sean.ohalpin@...> 2008/11/04

On Tue, Nov 4, 2008 at 2:38 PM, Ken Bloom <kbloom@gmail.com> wrote:

[#319395] Re: FFI 0.1.1 (Foreign Function Interface) for Ruby 1.8.6/7 and 1.9 — Nit Khair <sentinel.2001@...> 2008/11/04

Sean O'halpin wrote:

[#319428] Re: FFI 0.1.1 (Foreign Function Interface) for Ruby 1.8.6/7 and 1.9 — Charles Oliver Nutter <charles.nutter@...> 2008/11/04

Nit Khair wrote:

[#319467] Re: FFI 0.1.1 (Foreign Function Interface) for Ruby 1.8.6/7 and 1.9 — "Sean O'Halpin" <sean.ohalpin@...> 2008/11/05

On Tue, Nov 4, 2008 at 7:02 PM, Charles Oliver Nutter

[#319468] Re: FFI 0.1.1 (Foreign Function Interface) for Ruby 1.8.6/7 and 1.9 — Charles Oliver Nutter <charles.nutter@...> 2008/11/05

Sean O'Halpin wrote:

[#319535] Re: FFI 0.1.1 (Foreign Function Interface) for Ruby 1.8.6/7 and 1.9 — "Sean O'Halpin" <sean.ohalpin@...> 2008/11/05

On Wed, Nov 5, 2008 at 4:34 AM, Charles Oliver Nutter

[#319538] Re: FFI 0.1.1 (Foreign Function Interface) for Ruby 1.8.6/7 and 1.9 — Nit Khair <sentinel.2001@...> 2008/11/05

Sean O'halpin wrote:

[ANN] main-2.8.3

From: ara howard <ara.t.howard@...>
Date: 2008-10-23 03:21:29 UTC
List: ruby-talk #318389

NAME
   main.rb

SYNOPSIS
   a class factory and dsl for generating command line programs real  
quick

URI
   http://codeforpeople.com/lib/ruby/
   http://rubyforge.org/projects/codeforpeople/
   http://codeforpeople.rubyforge.org/svn/

INSTALL
   gem install main

DESCRIPTION
   main.rb features the following:

     - unification of option, argument, keyword, and environment  
parameter
       parsing
     - auto generation of usage and help messages
     - support for mode/sub-commands
     - io redirection support
     - logging hooks using ruby's built-in logging mechanism
     - intelligent error handling and exit codes
     - use as dsl or library for building Main objects
     - parsing user defined ARGV and ENV
     - zero requirements for understanding the obtuse apis of *any*  
command
       line option parsers
     - leather pants

   in short main.rb aims to drastically lower the barrier to writing  
uniform
   command line applications.

   for instance, this program

     require 'main'

     Main {
       argument 'foo'
       option 'bar'

       def run
         p params['foo']
         p params['bar']
         exit_success!
       end
     }

   sets up a program which requires one argument, 'bar', and which may  
accept one
   command line switch, '--foo' in addition to the single option/mode  
which is always
   accepted and handled appropriately: 'help', '--help', '-h'.  for  
the most
   part main.rb stays out of your command line namespace but insists  
that your
   application has at least a help mode/option.

   main.rb supports sub-commands in a very simple way

     require 'main'

     Main {
       mode 'install' do
         def run() puts 'installing...' end
       end

       mode 'uninstall' do
         def run() puts 'uninstalling...' end
       end
     }

   which allows a program, called 'a.rb', to be invoked as

     ruby a.rb install

   and

     ruby a.rb uninstall

   for simple programs main.rb is a real time saver but it's for more  
complex
   applications where main.rb's unification of parameter parsing, class
   configuration dsl, and auto-generation of usage messages can really  
streamline
   command line application development.  for example the following  
'a.rb'
   program:

     require 'main'

     Main {
       argument('foo'){
         cast :int
       }
       keyword('bar'){
         arity 2
         cast :float
         defaults 0.0, 1.0
       }
       option('foobar'){
         argument :optional
         description 'the foobar option is very handy'
       }
       environment('BARFOO'){
         cast :list_of_bool
         synopsis 'export barfoo=value'
       }

       def run
         p params['foo'].value
         p params['bar'].values
         p params['foobar'].value
         p params['BARFOO'].value
       end
     }

   when run with a command line of

     BARFOO=true,false,false ruby a.rb 42 bar=40 bar=2 --foobar=a

   will produce

     42
     [40.0, 2.0]
     "a"
     [true, false, false]

   while a command line of

     ruby a.rb --help

   will produce

     NAME
       a.rb

     SYNOPSIS
       a.rb foo [bar=bar] [options]+

     PARAMETERS
       * foo [ 1 -> int(foo) ]

       * bar=bar [ 2 ~> float(bar=0.0,1.0) ]

       * --foobar=[foobar] [ 1 ~> foobar ]
           the foobar option is very handy

       * --help, -h

       * export barfoo=value

   and this shows how all of argument, keyword, option, and  
environment parsing
   can be declartively dealt with in a unified fashion - the dsl for all
   parameter types is the same - and how auto synopsis and usage  
generation saves
   keystrokes.  the parameter synopsis is compact and can be read as

       * foo [ 1 -> int(foo) ]

         'one argument will get processed via int(argument_name)'

           1        : one argument
           ->       : will get processed (the argument is required)
           int(foo) : the cast is int, the arg name is foo

       * bar=bar [ 2 ~> float(bar=0.0,1.0) ]

         'two keyword arguments might be processed via  
float(bar=0.0,1.0)'

           2                  : two arguments
           ~>                 : might be processed (the argument is  
optional)
           float(bar=0.0,1.0) : the cast will be float, the default  
values are
                                0.0 and 1.0

       * --foobar=[foobar] [ 1 ~> foobar ]

         'one option with optional argument may be given directly'

       * --help, -h

         no synopsis, simple switch takes no args and is not required

       * export barfoo=value

         a user defined synopsis

SAMPLES

   <========< samples/a.rb >========>

   ~ > cat samples/a.rb

     require 'main'

     ARGV.replace %w( 42 ) if ARGV.empty?

     Main {
       argument('foo'){
         required                    # this is the default
         cast :int                   # value cast to Fixnum
         validate{|foo| foo == 42}   # raises error in failure case
         description 'the foo param' # shown in --help
       }

       def run
         p params['foo'].given?
         p params['foo'].value
       end
     }

   ~ > ruby samples/a.rb

     true
     42

   ~ > ruby samples/a.rb --help

     NAME
       a.rb

     SYNOPSIS
       a.rb foo [options]+

     PARAMETERS
       foo (1 -> int(foo))
           the foo param
       --help, -h



   <========< samples/b.rb >========>

   ~ > cat samples/b.rb

     require 'main'

     ARGV.replace %w( 40 1 1 ) if ARGV.empty?

     Main {
       argument('foo'){
         arity 3                             # foo will given three  
times
         cast :int                           # value cast to Fixnum
         validate{|foo| [40,1].include? foo} # raises error in failure  
case
         description 'the foo param'         # shown in --help
       }

       def run
         p params['foo'].given?
         p params['foo'].values
       end
     }

   ~ > ruby samples/b.rb

     true
     [40, 1, 1]

   ~ > ruby samples/b.rb --help

     NAME
       b.rb

     SYNOPSIS
       b.rb foo foo foo [options]+

     PARAMETERS
       foo (3 -> int(foo))
           the foo param
       --help, -h



   <========< samples/c.rb >========>

   ~ > cat samples/c.rb

     require 'main'

     ARGV.replace %w( foo=40 foo=2 bar=false ) if ARGV.empty?

     Main {
       keyword('foo'){
         required  # by default keywords are not required
         arity 2
         cast :float
       }
       keyword('bar'){
         cast :bool
       }

       def run
         p params['foo'].given?
         p params['foo'].values
         p params['bar'].given?
         p params['bar'].value
       end
     }

   ~ > ruby samples/c.rb

     true
     [40.0, 2.0]
     true
     false

   ~ > ruby samples/c.rb --help

     NAME
       c.rb

     SYNOPSIS
       c.rb foo=foo [bar=bar] [options]+

     PARAMETERS
       foo=foo (2 -> float(foo))
       bar=bar (1 ~> bool(bar))
       --help, -h



   <========< samples/d.rb >========>

   ~ > cat samples/d.rb

     require 'main'

     ARGV.replace %w( --foo=40 -f2 ) if ARGV.empty?

     Main {
       option('foo', 'f'){
         required  # by default options are not required, we could use  
'foo=foo'
                   # above as a shortcut
         argument_required
         arity 2
         cast :float
       }

       option('bar=[bar]', 'b'){  # note shortcut syntax for optional  
args
         # argument_optional      # we could also use this method
         cast :bool
         default false
       }

       def run
         p params['foo'].given?
         p params['foo'].values
         p params['bar'].given?
         p params['bar'].value
       end
     }

   ~ > ruby samples/d.rb

     true
     [40.0, 2.0]
     nil
     false

   ~ > ruby samples/d.rb --help

     NAME
       d.rb

     SYNOPSIS
       d.rb --foo=foo [options]+

     PARAMETERS
       --foo=foo, -f (2 -> float(foo))
       --bar=[bar], -b (0 ~> bool(bar=false))
       --help, -h



   <========< samples/g.rb >========>

   ~ > cat samples/g.rb

     require 'main'

     ARGV.replace %w( 42 ) if ARGV.empty?

     Main {
       argument( 'foo' )
       option( 'bar' )

       run { puts "This is what to_options produces:  
#{params.to_options.inspect}" }
     }

   ~ > ruby samples/g.rb

     This is what to_options produces: {"help"=>nil, "foo"=>"42",  
"bar"=>nil}

   ~ > ruby samples/g.rb --help

     NAME
       g.rb

     SYNOPSIS
       g.rb foo [options]+

     PARAMETERS
       foo (1 -> foo)
       --bar
       --help, -h



   <========< samples/h.rb >========>

   ~ > cat samples/h.rb

     require 'main'

     # block-defaults are instance_eval'd in the main instance and can  
be combined with
     # mixins
     #
     # ./h.rb   #=> forty-two
     # ./h.rb a #=> 42
     # ./h.rb b #=> 42.0
     #

     Main {
       fattr :default_for_foobar => 'forty-two'

       option(:foobar) do
         default{ default_for_foobar }
       end

       mixin :foo do
         fattr :default_for_foobar => 42
       end

       mixin :bar do
         fattr :default_for_foobar => 42.0
       end


       run{ p params[:foobar].value }

       mode :a do
         mixin :foo
       end

       mode :b do
         mixin :bar
       end
     }

   ~ > ruby samples/h.rb

     "forty-two"

   ~ > ruby samples/h.rb --help

     NAME
       h.rb

     SYNOPSIS
       h.rb (a|b) [options]+

     PARAMETERS
       --foobar
       --help, -h



DOCS
   test/main.rb

   vim -p lib/main.rb lib/main/*rb

   API section below

HISTORY
   2.8.3
     - support for block defaults

API

   Main {

    
###########################################################################
   #                       CLASS LEVEL  
API                                   #
    
###########################################################################
   #
   # the name of the program, auto-set and used in usage
   #
     program 'foo.rb'
   #
   # a short description of program functionality, auto-set and used  
in usage
   #
     synopsis "foo.rb arg [options]+"
   #
   # long description of program functionality, used in usage iff set
   #
     description <<-hdoc
       this text will automatically be indented to the right level.

       it should describe how the program works in detail
     hdoc
   #
   # used in usage iff set
   #
     author 'ara.t.howard@gmail.com'
   #
   # used in usage
   #
     version '0.0.42'
   #
   # stdin/out/err can be anthing which responds to read/write or a  
string
   # which will be opened as in the appropriate mode
   #
     stdin '/dev/null'
     stdout '/dev/null'
     stderr open('/dev/null', 'w')
   #
   # the logger should be a Logger object, something 'write'-able, or  
a string
   # which will be used to open the logger.  the logger_level  
specifies the
   # initalize verbosity setting, the default is Logger::INFO
   #
     logger(( program + '.log' ))
     logger_level Logger::DEBUG
   #
   # you can configure exit codes.  the defaults are shown
   #
     exit_success # 0
     exit_failure # 1
     exit_warn    # 42
   #
   # the usage object is rather complex.  by default it's an object  
which can
   # be built up in sections using the
   #
   #   usage["BUGS"] = "something about bugs'
   #
   # syntax to append sections onto the already pre-built usage  
message which
   # contains program, synopsis, parameter descriptions and the like
   #
   # however, you always replace the usage object wholesale with one  
of your
   # chosing like so
   #
     usage <<-txt
       my own usage message
     txt

    
###########################################################################
   #                         MODE  
API                                        #
    
###########################################################################
   #
   # modes are class factories that inherit from their parent class.   
they can
   # be nested *arbitrarily* deep.  usage messages are tailored for  
each mode.
   # modes are, for the most part, independant classes but parameters  
are
   # always a superset of the parent class - a mode accepts all of  
it's parents
   # paramters *plus* and additional ones
   #
     option 'inherited-option'
     argument 'inherited-argument'

     mode 'install' do
       option 'force' do
         description 'clobber existing installation'
       end

       def run
         inherited_method()
         puts 'installing...'
       end

       mode 'docs' do
         description 'installs the docs'

         def run
           puts 'installing docs...'
         end
       end
     end

     mode 'un-install' do
       option 'force' do
         description 'remove even if dependancies exist'
       end

       def run
         inherited_method()
         puts 'un-installing...'
       end
     end

     def run
       puts 'no mode yo?'
     end

     def inherited_method
       puts 'superclass_method...'
     end


    
###########################################################################
   #                         PARAMETER  
API                                   #
    
###########################################################################
   #
   # all the parameter types of argument|keyword|option|environment  
share this
   # api.  you must specify the type when the parameter method is used.
   # alternatively used one of the shortcut methods
   # argument|keyword|option|environment.  in otherwords
   #
   #   parameter('foo'){ type :option }
   #
   # is synonymous with
   #
   #   option('foo'){ }
   #
     option 'foo' {
     #
     # required - whether this paramter must by supplied on the  
command line.
     # note that you can create 'required' options with this keyword
     #
       required # or required true
     #
     # argument_required - applies only to options.
     #
       argument_required # argument :required
     #
     # argument_optional - applies only to options.
     #
       argument_optional # argument :optional
     #
     # cast - should be either a lambda taking one argument, or a symbol
     # designation one of the built in casts defined in Main::Cast.   
supported
     # types are :boolean|:integer|:float|:numeric|:string|:uri.   
built-in
     # casts can be abbreviated
     #
       cast :int
     #
     # validate - should be a lambda taking one argument and returning
     # true|false
     #
       validate{|int| int == 42}
     #
     # synopsis - should be a concise characterization of the  
paramter.  a
     # default synopsis is built automatically from the parameter.  this
     # information is displayed in the usage message
     #
       synopsis '--foo'
     #
     # description - a longer description of the paramter.  it appears  
in the
     # usage also.
     #
       description 'a long description of foo'
     #
     # arity - indicates how many times the parameter should appear on  
the
     # command line.  the default is one.  negative arities are  
supported and
     # follow the same rules as ruby methods/procs.
     #
       arity 2
     #
     # default - you can provide a default value in case none is  
given.  the
     # alias 'defaults' reads a bit nicer when you are giving a list of
     # defaults for paramters of > 1 arity
     #
       defaults 40, 2
     #
     # you can add custom per-parameter error handlers using the  
following
     #
       error :before do
         puts 'this fires *before* normal error handling using  
#instance_eval...'
       end

       error do
         puts 'this fires *instead of* normal error handling using  
#instance_eval...'
       end

       error :after do
         puts 'this fires *after* normal error handling using  
#instance_eval...'
       end
     }

    
###########################################################################
   #                       INSTANCE LEVEL  
API                                #
    
###########################################################################
   #
   # you must define a run method.  it is the only method you must  
define.
   #
     def run
       #
       # all parameters are available in the 'params' hash and via the  
alias
       # 'param'.  it can be indexed via string or symbol.  the values  
are all
       # Main::Parameter objects
       #
         foo = params['foo']
       #
       # the given? method indicates whether or not the parameter was  
given on
       # the commandline/environment, etc.  in particular this will  
not be true
       # when a default value was specified but no parameter was given
       #
         foo.given?
       #
       # the list of all values can be retrieved via 'values'.  note  
that this
       # is always an array.
       #
         p foo.values
       #
       # the __first__ value can be retrieved via 'value'.  note that  
this
       # never an array.
       #
         p foo.value
       #
       # the methods debug|info|warn|error|fatal are delegated to the  
logger
       # object
       #
         info{ "this goes to the log" }
       #
       # you can set the exit_status at anytime.  this status is used  
when
       # exiting the program.  exceptions cause this to be ext_failure  
if, and
       # only if, the current value was exit_success.  in otherwords an
       # un-caught exception always results in a failing exit_status
       #
         exit_status exit_failure
       #
       # a few shortcuts both set the exit_status and exit the program.
       #
         exit_success!
         exit_failure!
         exit_warn!
     end

   }



enjoy.


a @ http://codeforpeople.com/
--
we can deny everything, except that we have the possibility of being  
better. simply reflect on that.
h.h. the 14th dalai lama




In This Thread

Prev Next