Skip to content

Instantly share code, notes, and snippets.

@migane
Created September 3, 2012 18:09
Show Gist options
  • Save migane/3611582 to your computer and use it in GitHub Desktop.
Save migane/3611582 to your computer and use it in GitHub Desktop.
input number with rack
# input_number.rb
def input_response(n)
answer = ""
if n > 0
answer = "positive"
elsif n < 0
answer = "negative"
else n == 0
answer = "zero"
end
return answer
end
error = false
n = ARGV[0].to_i
def check_input
if ARGV.length < 1 || ARGV.length > 1
error = true
elsif
begin
n = Integer(ARGV[0])
rescue ArgumentError
error = true
end
end
return error
end
my_rack_proc = lambda { |env| [200, {"Content-Type" => "text/plain"},
[check_input == true ? "Please, enter an integer as argument" :"The number you entered on the command line is " + input_response(n)]]}
puts my_rack_proc.call({})
Copy link

ghost commented Sep 3, 2012

Nice.

@migane
Copy link
Author

migane commented Sep 4, 2012

def check_input
if ARGV.length < 1 || ARGV.length > 1
error = true
elsif #=> should be else not elsif
begin
n = Integer(ARGV[0])
rescue ArgumentError
error = true
end
end
return error
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment