Skip to content

Instantly share code, notes, and snippets.

@harmesy
Created April 1, 2012 21:43
Show Gist options
  • Save harmesy/55ecd17e554d0818bd47 to your computer and use it in GitHub Desktop.
Save harmesy/55ecd17e554d0818bd47 to your computer and use it in GitHub Desktop.
Grab a random word. For when you're too lazy to be creative.
#!/usr/bin/env ruby
word_list = []
generate_word = true
File.open("/usr/share/dict/words") do |words|
words.each { |word| word_list << word.strip }
end
puts "Grabbing a random word:"
while generate_word
word = word_list[rand(word_list.length)]
puts word
print 'Hit "y" if you want this one. Hit "n" to generate a new word: '
while true
response = gets
case response.strip
when "y"
IO.popen('pbcopy', 'w').print word
generate_word = false
break
when "n"
break
else
print "Sorry, didn't understand that one. Try again: "
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment