Created
September 4, 2012 10:31
-
-
Save migane/3619842 to your computer and use it in GitHub Desktop.
Reverse world in sentence with rack
This file contains hidden or 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
| #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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool