Skip to content

Instantly share code, notes, and snippets.

@nickmccurdy
Last active October 13, 2015 01:18
Show Gist options
  • Save nickmccurdy/4116668 to your computer and use it in GitHub Desktop.
Save nickmccurdy/4116668 to your computer and use it in GitHub Desktop.
Quotes Script
#!/usr/bin/env ruby
# quotes.rb
# Picks a random quote from quotes.txt and prints it to stdout.
# Quotes should be separated by double newlines (single empty lines) in the file.
# We need to define Array#sample if this version of Ruby is really old.
unless Array.respond_to? 'sample'
class Array
def sample
self[rand(length)]
end
end
end
# Here we go!
puts File.open("#{File.dirname __FILE__}/quotes.txt").read.split(/\n\n/).sample
"Many people ask what are Beatles? Why Beatles? Ugh, Beatles, how did the name arrive? So we will tell you. It came in a vision--a man appeared in a flaming pie and said unto them 'From this day on you are Beatles with an A.' 'Thank you, Mister Man,' they said, thanking him." - John Lennon
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." - Albert Einstein
"I reject your reality and substitute my own!" - Adam Savage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment