Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- # coding: utf-8
- $KCODE = 'u'
- module Prompt
- def prompt(question, params = {})
- question += " [#{params[:default]}]" if params[:default]
- print "#{question}: "
- answer = gets.chop
- answer = params[:default] if params[:default] and answer == ''
- answer
- end
- end
- include Prompt
- name = prompt "What's your name?", :default => 'Allan Smithee'
- puts "Your name is #{name}"
Add Comment
Please, Sign In to add comment