Thairuby ->a, b {a + b} wrote:
> Is this ok? But it still use variable :(
> 
> file.each_line { |line|
>   if line =~ (a ||= $line_patterns["pattern a"])
>     process_pattern_a(line)
>   elsif line =~ (b ||= $line_patterns["pattern b"])
>     process_pattern_b(line)
>   # some more elsifs
>   end
> }

I'm wrong typing. It would be

file.each_line { |line|
  if line =~ (a ||= /^pattern[a]*/)
    process_pattern_a(line)
  elsif line =~ (b ||= /pat+e(rn)? b\s*$/)
    process_pattern_b(line)
  # some more elsifs
  end
}

Does it have o option for string? :)
-- 
Posted via http://www.ruby-forum.com/.