Skip to content

Instantly share code, notes, and snippets.

@rickhull
Last active December 17, 2015 22:29
Show Gist options
  • Save rickhull/5682286 to your computer and use it in GitHub Desktop.
Save rickhull/5682286 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
def usage(msg = nil)
puts "ERROR: #{msg}" if msg
puts <<EOF
USAGE:
doubler.rb num
EOF
exit 1
end
require 'doubler'
num = ARGV.shift || usage("No target provided")
puts "#{num} doubled: #{Doubler.double(num)}"
module Doubler
def self.double(num)
# handle strings, convert to float or integer intelligently
if num.is_a?(String)
if num.index '.'
num = num.to_f
else
num = num.to_i
end
end
2 * num
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment