From: "Ara.T.Howard" Date: 2003-12-02T00:42:11+09:00 Subject: Re: anything disappearing from Ruby for 2.0? On Mon, 1 Dec 2003, Yukihiro Matsumoto wrote: > Date: Mon, 1 Dec 2003 23:49:32 +0900 > From: Yukihiro Matsumoto > Newsgroups: comp.lang.ruby > Subject: Re: anything disappearing from Ruby for 2.0? > > Hi, > > In message "Re: anything disappearing from Ruby for 2.0?" > on 03/12/01, Carlos writes: > > |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? > > I like the basic idea. the "shortcut notation" would be a key. I > couldn't think of a good one for years. But someone might be able to. > > matz. how about extending readlines and defining an IO#[] method: class IO def readlines range = nil ... end def [] fixnum_or_range_of_fixnum_or_regexp ... end end lines = IO.readlines /abc/ .. /def/ open(path) do |f| lines = f[ /abc/ .. /def/ ] end #[] could also work as a 'seek and read' type operator. record = f[offset, length] -a -- ATTN: please update your address books with address below! =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328 | STP :: http://www.ngdc.noaa.gov/stp/ | NGDC :: http://www.ngdc.noaa.gov/ | NESDIS :: http://www.nesdis.noaa.gov/ | NOAA :: http://www.noaa.gov/ | US DOC :: http://www.commerce.gov/ | | The difference between art and science is that science is what we | understand well enough to explain to a computer. | Art is everything else. | -- Donald Knuth, "Discover" | | /bin/sh -c 'for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done' ===============================================================================