Skip to content

Instantly share code, notes, and snippets.

@joshbuddy
Created August 30, 2009 20:02
Show Gist options
  • Save joshbuddy/178106 to your computer and use it in GitHub Desktop.
Save joshbuddy/178106 to your computer and use it in GitHub Desktop.
require 'lib/usher'
u = Usher::Interface.for(:text) do
on('my name is :name') { |name|
puts "hey #{name}, nice to meet you"
}
on('hey :first_name( :last_name)') {|first_name, last_name|
puts last_name ?
"how are you doing #{first_name} #{last_name}?" :
"how are you doing #{first_name}?"
}
on_with_hash('ilya is the :adjective1( :adjective2( :adjective3)) guy') { |hash|
puts "i heard somewhere ilya is #{hash.inspect}"
}
on('ilya is seriously the (*adjective) guy') { |adjective|
puts "whoa, seriously #{adjective.join(', ')} and more!"
}
end
u.run('my name is usher')
# hey usher, nice to meet you
u.run('hey joshua')
# how are you doing joshua?
u.run('hey joshua hull')
# how are you doing joshua hull?
u.run('ilya is the nicest guy')
# i heard somewhere ilya is {:adjective1=>"nicest"}
u.run('ilya is the nicest greatest guy')
# i heard somewhere ilya is {:adjective1=>"nicest", :adjective2=>"greatest"}
u.run('ilya is the nicest greatest smartest guy')
# i heard somewhere ilya is {:adjective3=>"smartest", :adjective1=>"nicest", :adjective2=>"greatest"}
u.run('ilya is seriously the nicest greatest smartest guy')
# whoa, seriously nicest, greatest, smartest and more!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment