secret
Created

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#!/usr/bin/env ruby
 
to_test = Enumerable
total = to_test.public_instance_methods.map(&:to_s)
guessed = []
 
puts "How many methods of #{to_test} can you name?"
puts "Press Control-D to exit"
print "1. "
 
while guessed.count < total.count && (guess = gets)
guess.chomp!
if total.include? guess
if guessed.include? guess
puts "You already got \"#{guess}\""
else
guessed << guess
puts "OK!"
end
else
puts "Sorry!"
end
 
print "#{guessed.count + 1}. " if guessed.count < total.count
end
 
missed = total - guessed
puts
puts missed.empty? ? "You got them all!" : "You missed:"
puts missed.sort.map { |name| "\t" + name }
puts "#{guessed.count} / #{total.count} methods named"

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.