From: Gary Wright Date: 2009-09-28T04:57:45+09:00 Subject: Re: handling of regexp objects that aren't referenced by variables, arrays, tables or objects 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