Monthly Archive:: April 2006

Ruby: Searching for a variable string using grep

I was looking for a way to search for a variable string inside a ruby method and I think I have found _a_ solution. def print_line_containing(file, str) File.open(file).grep(/#{str}/).each do |line| puts "#{line}" endenddef print_line_containing(file, str1, str2) File.open(file).grep(/#{str1}\s+#{str2}/).each do |line| puts "#{line}" endend ...Read More