Method: Sequel::Dataset#escape_like

Defined in:
lib/sequel/dataset/misc.rb

#escape_like(string) ⇒ Object

Returns the string with the LIKE metacharacters (% and _) escaped. Useful for when the LIKE term is a user-provided string where metacharacters should not be recognized. Example:

ds.escape_like("foo\\%_") # 'foo\\\%\_'


68
69
70
# File 'lib/sequel/dataset/misc.rb', line 68

def escape_like(string)
  string.gsub(/[\\%_]/){|m| "\\#{m}"}
end