Skip to content

Instantly share code, notes, and snippets.

@migane
Created September 4, 2012 10:31
Show Gist options
  • Select an option

  • Save migane/3619842 to your computer and use it in GitHub Desktop.

Select an option

Save migane/3619842 to your computer and use it in GitHub Desktop.
Reverse world in sentence with rack
#my_rack_mtd.rb
require 'rack'
error = false
def check_argument
if (ARGV.length < 1 || ARGV.length > 1 || ARGV[0].split(" ").size < 2)
error = true
end
return error
end
def reverse_word_order(env)
[200, {}, [check_argument ? "Enter one sentence with at least two words to reverse the sentence" : ARGV[0].split(" ").reverse.join(" ")]]
end
Rack::Handler::Thin.run method(:reverse_word_order)
Copy link

ghost commented Sep 4, 2012

Cool

@RajeshHuria
Copy link

much simpler than mine ;)

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