Last active
December 17, 2015 22:29
-
-
Save rickhull/5682286 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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)}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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