Skip to content

Instantly share code, notes, and snippets.

@dcoxall
Last active December 20, 2015 04:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcoxall/6073505 to your computer and use it in GitHub Desktop.
Save dcoxall/6073505 to your computer and use it in GitHub Desktop.
A quick script to demonstrate an easy way to execute ruby
#!/usr/bin/env ruby
require 'trollop'
class Command
def initialize(options = {})
@default_name = options[:name]
end
def execute
name = ask "Hello, ...?" unless name = @default_name
say "Hello, #{name}!"
rescue Interrupt
puts "\n\n"
say "Okay then... Good bye!"
end
private
def say(text)
$stdout.puts text.to_s
end
def ask(text)
say(text)
$stdout.print '> '
result = $stdin.gets.chomp
$stdout.puts
result
end
end
options = Trollop::options do
opt :name, "The default name to use", type: :string
end
command = Command.new(options)
command.execute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment