I am new to Ruby and Rails. I am playing with Rack, trying to get a basic understanding of this peice of the Rails puzzle, following along with Rob Conery in his Tekpub/Rails 3 tutorial vid.
Unfortunately, the version of Rack used in the vid has become long in the tooth, and I think something has changed in between the video release and now (as have some things in Ruby between 1.8.x and 1.9.x). Even more unfortunately, I don't yet know enough about Ruby or Rack to know how to figure out what I need to do differently. The version of Rack used in the video is 1.1. The version on my machine is 1.4.5.
Silly example code:
class EnvironmentOutput
def intialize(app)
@app = app
end
def call(env)
out = ""
unless(@app.nil?)
response = @app.call(env)[1]
out+=response
end
env.keys.each {|key| out+="<li>#{key}=#{env[key]}"}
["200", {"Content-Type" => "text/html"}, [out]]
end
end
class MyApp
def call(env)
["200", {"Content-Type" => "text/html"}, ["<h1>Hello There</h1>"]]
end
end
# My understanding is that this should work:
use EnvironmentOutput
run MyApp.new
When I run this, I get the following:
ArgumentError: wrong number of arguments(1 for 0)
This is where the first in a series of errors occurs (line 82 in the rack Builder
class):
def use(middleware, *args, &block)
if @map
mapping, @map = @map, nil
@use << proc { |app| generate_map app, mapping }
end
# error occurs HERE:
@use << proc { |app| middleware.new(app, *args, &block) }
end
Obviously, I am passing something incorrectly. Sadly, I don't yet know enough to figure out what it is I am doing wrong. I have searched on Google and here on SO, but I suspect I also don't have quite a strong enough grasp on the Ruby/Rails/Rack relationship to know what to ask and get a reasonably helpful result (or, if I AM, then I don't yet recognize it).
Does anyone know what I am doing wrong here?
UPDATE: Thanks to the selected answer, I realize it was a typo. Next issue is an array-to-string conversion problem in the same code, but will post as new question.