Ruby check if variable exists in a file -


i have text file of 1 word per line.

i want check if ruby variable exists on lines in file.

@username = john

and in bannedwords.txt:

alex adam mary john james 

so true. best function use in ruby this?

just read in file , convert set can use test inclusion:

require 'set' banned = set.new(file.readlines('bannedwords.txt').collect(&:chomp))  banned.include?('john') # => true  banned.include?('papa smurf') # => false 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -