1

This doesn't work:

run Proc.new do |env|
  [200, 
   {
    "Content-Type" => "application/json; charset=UTF-8"
  }, ["{\"name\":\"Rack App\"}"]]
end

But this does:

run Proc.new { |env|
  [200, 
   {
    "Content-Type" => "application/json; charset=UTF-8"
  }, ["{\"name\":\"Rack App\"}"]]
}

Any ideas, why its throwing error when used with do..end?

Error I am getting:

app.ru:1:in new: tried to create Proc object without a block (ArgumentError)

Jikku Jose
  • 18,306
  • 11
  • 41
  • 61
  • 1
    `do end` vs `{ }` has different precedence so it may be run something like `run do; # code end; Proc.new` but `{}` may run this as you intended: `proc11 = Proc.new {; # code }; run proc11`. Well, that I think is the problem but I don't know rack too much so, that's why it is a comment not an answer. – Darek Nędza Aug 09 '14 at 09:56

1 Answers1

2

Your first code is interpreted as:

run(Proc.new) do |env|
  ...
end

and the block is is passed to run instead of new. The problem can be solved by doing:

run(Proc.new do |env|
  ...
end)
sawa
  • 165,429
  • 45
  • 277
  • 381