Detect a Secret Knock message after a given timeout

#!/usr/bin/env ruby

require 'io/console'
require 'logger'
require 'secret_knock'

c = ' '

sk =


def sk.on_timeout(msg) 
  logger = 'sk.log'
  puts ':: ' + msg.inspect
  logger.debug  '::' + msg.inspect

puts 'press the space bar to knock, or any other key to exit'
sk.knock while (c = $stdin.getch ) == ' ' and sk.listening

puts "Your message was " + sk.message

In the above example a secret message can be knocked out and logged to the local file sk.log. By default the the SecretKnock#detect method will wait for 2 seconds before it executes the SecretKnock#on_timemout method and then listens again for more secret knock messages.