From: Trans Date: 2007-06-21T23:50:58+09:00 Subject: Re: GetoptLong, but not on ARGV On Jun 21, 4:04 am, "Robert Dober" wrote: > On 6/21/07, Trans wrote: > > > Ah, so we need a patch. Okay well I guess I'll post that up on the > > board too. > > Yes definitely ARGV is hardcoded, I was however fooling around, trying > to make a patch in less than a minute, which worked ;). > > If you really want to send up a patch, please consider this one (it is > a correct patch created with diff -u this time too): > > It does *not* temper with internal state, just allows an array to be > passed to #each or #get. I tested it with this use case: > > ------------------ 8< ------------------------- > require 'getoptlong' > > opt = GetoptLong.new([ '-x', GetoptLong::NO_ARGUMENT ],[ '-b', > GetoptLong::REQUIRED_ARGUMENT]) > > blk = lambda do > |*v| > puts v.join(": ") > end > opt.dup.each %w{ -x -b 1024}, &blk > > opt.dup.each %w{ -b 4096 }, &blk > ------------------------------ 8<--------------------------- > > Please note the necessity of dup for reuse, I did not want to bother > with internal state of a class I do not understand and I have no time > to dig into :(. > > Cheers > Robert I think i would be better to do: def argslist @argslist ||= ARGV # or ARGV.dup end def argslist=(array) @argslist = array.to_ary end and then /argslist/ARGV/g T.