Add string extension
This commit is contained in:
parent
aa1928303d
commit
81607e68c4
|
@ -1,6 +1,18 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class String
|
class String
|
||||||
|
def to_escaped_for_sql_like
|
||||||
|
gsub(/%|_|\*|\\\*|\\\\|\\/) do |str|
|
||||||
|
case str
|
||||||
|
when "%" then '\%'
|
||||||
|
when "_" then '\_'
|
||||||
|
when "*" then "%"
|
||||||
|
when '\*' then "*"
|
||||||
|
when "\\\\", "\\" then "\\\\"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def truthy?
|
def truthy?
|
||||||
match?(/\A(true|t|yes|y|on|1)\z/i)
|
match?(/\A(true|t|yes|y|on|1)\z/i)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user