Skip to content

Instantly share code, notes, and snippets.

@oddlyfunctional
Last active July 27, 2016 23:57
Show Gist options
  • Save oddlyfunctional/1bb2b13c03ad08f10bdfddc40dbd887e to your computer and use it in GitHub Desktop.
Save oddlyfunctional/1bb2b13c03ad08f10bdfddc40dbd887e to your computer and use it in GitHub Desktop.
Find adjectives in standard UNIX dictionary of words
words_path = [
'/usr/share/dict/words'
'/usr/dict/words'
].find { |path| File.exists?(path) }
fail "Couldn't find words file in the system" unless words_path
# I’m using each_line so we don’t load everything
# into memory at once, since the file is huge.
awesome_adjectives = File.open(words_path, 'r')
.each_line
.select { |line| line =~ /^[a-z].*ly$/ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment