Hi --

On Sun, 27 Aug 2006, Oliver Bandel wrote:

> dblack / wobblini.net wrote:
>
>> Hi --
>> 
>> On Sat, 26 Aug 2006, William James wrote:
>> 
>>> Oliver Bandel wrote:
>>> 
>>>> Hello,
>>>> 
>>>> 
>>>> The Code:
>>>> 
>>>> ====================================
>>>> def look_for_begin
>>>>    while line = gets
>>>>      if line =~ /^begin/
>>>>        puts line
>>>>        # return
>>>>      end
>>>>    end
>>>> end
>>>> 
>>>> ARGF.each { look_for_begin }
>>>> ====================================
>>> 
>>> 
>>> puts ARGV.map{|f|IO.readlines(f).find{|s|s=~/^begin/}}
>> 
>> 
>> Or maybe:
>>
>>   puts ARGF.find {|s| /^begin/.match(s) }
> [...]
>
> Theese both things looks like if they would look for *all*
> occurrnces of "begin", not the first one.

Well, if you know how Enumerable#find works, then they look like they
find the first one :-)  (Though, as William pointed out, my code
answers the wrong question, because it only finds one for all the
files instead of one for each.)


David

-- 
http://www.rubypowerandlight.com => Ruby/Rails training & consultancy
   ----> SEE SPECIAL DEAL FOR RUBY/RAILS USERS GROUPS! <-----
http://dablog.rubypal.com        => D[avid ]A[. ]B[lack's][ Web]log
http://www.manning.com/black     => book, Ruby for Rails
http://www.rubycentral.org       => Ruby Central, Inc.