How to check if string contains a part of an array in Ruby? -
i have array of banned words in ruby:
bw = ["test"]
i want check @nick
against it.
for example
@nick = 'justatest'
would match.
i have tried:
if @nick.include?(bw) ## end
but doesn't seem right way doesn't catch it.
if concern check (as question's title suggests) then:
> bw.any? { |word| @nick[word] } => true
though might faster convert array of strings regexp:
> bw = ["test", "just", "gagan"] > g = /#{bw.join("|")}/ > g === @nick => true
Comments
Post a Comment