From: ThomasW Date: 2009-09-28T05:25:09+09:00 Subject: Re: handling of regexp objects that aren't referenced by variables, arrays, tables or objects On 27 Sep., 21:57, Gary Wright wrote: > On Sep 27, 2009, at 11:50 AM, ThomasW wrote: > > > I'm parsing text files and am using a lot of regexps for this. > > Initially I was doing something like this: > > > file.each_line { |line| > >  if line =~ /^pattern[a]*/ > >    process_pattern_a(line) > >  elsif line =~ /pat+e(rn)? b\s*$/ > >    process_pattern_b(line) > >  # some more elsifs > >  end > > } > > This example is perfect for Ruby's case statement: > > file.each_line { |line| >    case line >    when /^pattern[a]*/o >     process_pattern_a(line) >    when /pat+e(rn)? b\s*$/o >     process_pattern_b(line) >    # more when clauses >    else >      # handle no match >    end > > } > > Gary Wright Thanks for that tip. I wasn't aware that this also works with regexp matches. It's great that it does! By the way, is there anything substantially different from an elsif chain, except for being slightly less typing? Thomas W.