This question already has an answer here:
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)
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)
来源:https://stackoverflow.com/questions/25217274/proc-throws-error-when-used-with-do-end