From: dagbrown@... (Dave Brown) Date: 2003-12-02T04:42:09+09:00 Subject: Re: anything disappearing from Ruby for 2.0? In article <20031201143615.GA10473@quovadis.com.ar>, Carlos wrote: : > |Ack, no more: : > | : > |if (/foo/ .. /bar/) ? : > | : > |I find this construct terribly useful; I'd hate to see it go. : > : > Perhaps some other way to accomplish, for example, : > : > IO#from_to(re1, re2) {|line| ... } : > : > just an idea. : : Hi :) Here's another idea: : : 1) Make #.. a method (Integer#.. creates ranges, for example) : : 2) Make a shortcut to proc {...} (maybe "&{"? Anything, I don't know) : : 3) Define Proc#.. to work as a flip-flop : : 4) while &{ line =~ /abc/ }..&{ line =~ /def/ } : : Not as easy as before, but almost... : : What do you think? An operator .. would be nice. Lacking that, though, here's something I threw together in ten minutes: class FlipFlop class << self @@flipflopvalue = false # not thread safe, I imagine def flipflopon @@flipflopvalue = true end def flipflopoff @@flipflopvalue = false end def flipflopval @@flipflopvalue end end end class Object # Everything is true except false and nil...right? def until(rhs) FlipFlop.flipflopon end end module FalseFlipFlop def until(rhs) if (rhs) then FlipFlop.flipflopoff end FlipFlop.flipflopval end end class FalseClass include FalseFlipFlop end class NilClass include FalseFlipFlop end (The ability to do this kind of thing is what makes me say "Wow, what a great language Ruby is!" a lot.) I tested it with this: $ ls|ruby -rflipflop -ne 'print if ($_ =~ /^b/).until($_ =~ /^d/)' And it worked as I'd hoped it would. Unfortunately I couldn't define a method called "..". :-) --Dave