What is the best way to validate a gets input against a very long word list (a list of all the English words available)?
I am currently playing with readlines to manipulate the text, but before there’s any manipulation, I would like to first validate the entry against the list.
The simplest way, but by no means the fastest, is to simply search against the word list each time. If the word list is in an array:
If, however, you had the word list as a separate file (with each word on a separate line), then we’ll use
File#foreachto find it:Note that
foreachdoes not strip off the trailing newline character(s), so we get rid of them withString#chomp.