On Sat, 10 Feb 2007, Garance A Drosehn wrote:

>
> Besides, I wanted something which works for *any* routine which
> takes a code-block, not just objects of type Array.  How could you
> make that work for the each_pair method of Hash objects?
>
> I was thinking there should be some "big-picture" solution possible,
> one which would work for all methods which take a code-block
> parameter.  That is probably too complicated a goal, but at least a
> solution which would work for some large subset of those methods.
>

this pattern will work with most nearly any method

   harp:~ > cat a.rb
   require 'thread'

   argv = %w( -v 4 -l log foobar )

   q = SizedQueue.new 1
   done = Object.new.freeze
   t = Thread.new{ argv.each{|arg| q.push arg}; q.push done }

   while( arg = q.pop )
     break if arg == done
     case arg
     when '-v'
       p [arg, q.pop]
     when '-l'
       p [arg, q.pop]
     else
       p arg
     end
   end

   harp:~ > ruby a.rb
   ["-v", "4"]
   ["-l", "log"]
   "foobar"


it could be abstracted, but it's already pretty easy to use.

regards.

-a
-- 
we can deny everything, except that we have the possibility of being better.
simply reflect on that.
- the dalai lama