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

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -