Class: Rack::HanoiApp
- Inherits:
-
Object
- Object
- Rack::HanoiApp
- Defined in:
- lib/rack/hanoi.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(root, height, from = :A, to = :C, via = :B) ⇒ HanoiApp
constructor
A new instance of HanoiApp.
Constructor Details
Instance Method Details
#call(env) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rack/hanoi.rb', line 24 def call(env) env["rack.hanoi"] ||= "" logger = env["rack.logger"] || ::Logger.new(STDERR) if @height < 1 return Rack::Response.new do |res| res["Content-Type"] = "text/plain" res.body << with_lines(env["rack.hanoi"]) end.finish else HanoiApp.new(false, @height - 1, @from, @via, @to).call(env) logger.info "Disc Moved #{@from} to #{@to}" env["rack.hanoi"] << "Disc Moved #{@from} to #{@to}\n" HanoiApp.new(false, @height - 1, @via, @to, @from).call(env) end end |