A
Adam Akhtar
heres my function
def remove_for_such_and_such(a_string)
if (%r{(.+)for.*}i =~ a_string)
match = a_string.match(%r{(.+)for.*}i)
a_string = match[1].strip
end
a_string
end
i want to know if that could be written better. I wrote the if clause
because sometimes a string may not match the regular expression. If i
remove the "if" clause it might lead to match returning nil which will
stop my program. Im wondring is there a way to avoid using if?? if so it
could help performance especially if this function was used with huge
arrays of strings.
def remove_for_such_and_such(a_string)
if (%r{(.+)for.*}i =~ a_string)
match = a_string.match(%r{(.+)for.*}i)
a_string = match[1].strip
end
a_string
end
i want to know if that could be written better. I wrote the if clause
because sometimes a string may not match the regular expression. If i
remove the "if" clause it might lead to match returning nil which will
stop my program. Im wondring is there a way to avoid using if?? if so it
could help performance especially if this function was used with huge
arrays of strings.