From: Kristof Bastiaensen Date: 2004-04-23T23:04:09+09:00 Subject: Re: [NEWBIE] Extract all occurences from a text On Fri, 23 Apr 2004 13:52:10 +0000, gabriele renzi wrote: > il Fri, 23 Apr 2004 15:43:24 +0200, Kristof Bastiaensen > ha scritto:: > >>On Fri, 23 Apr 2004 05:08:00 -0700, David Alan Black wrote: >> >>>> >>>> you could simply do: >>>> >>>> lines=[] >> >>This line has no effect, the Array will be discarded >>at the next expression >> >>>> open(filename) do |f| >>>> lines= f.grep your_regexp >>>> end >>> > > just try it ;P > > If you do not initialize a variable outside of a block it will be > discarded when the block ends. > > This will change in ruby2 and work like you expect (I expect the > behaviour it has ATM) Of course you are right. Maybe initializing it to nil would be less expensive and make the purpose more clear.