* "run Proc.new" using "do ... end" fails ("{ }" required)
@ 2009-10-16 17:48 Iñaki Baz Castillo
2009-10-16 18:02 ` Yehuda Katz
0 siblings, 1 reply; 3+ messages in thread
From: Iñaki Baz Castillo @ 2009-10-16 17:48 UTC (permalink / raw)
To: Rack Development
Hi, the following works:
1 ::Rack::Builder.new do
2 map "/" do
3 run Proc.new { |env|
4 [ 404, {"Content-Type" => "text/plain"}), [""] ]
5 }
6 end
7 end
but the following gives an error:
1 ::Rack::Builder.new do
2 map "/" do
3 run Proc.new do |env|
4 [ 404, {"Content-Type" => "text/plain"}), [""] ]
5 end
6 end
7 end
/home/me/myfile.rb:3:in `new': tried to create Proc object without a block (ArgumentError)
from /home/me/myfile.rb:3:in `block (2 levels) in core'
from /usr/local/lib/ruby1.9/gems/1.9.1/gems/rack-1.0.0/lib/rack/builder.rb:29:in `instance_eval'
from /usr/local/lib/ruby1.9/gems/1.9.1/gems/rack-1.0.0/lib/rack/builder.rb:29:in `initialize'
from /usr/local/lib/ruby1.9/gems/1.9.1/gems/rack-1.0.0/lib/rack/builder.rb:46:in `new'
from /usr/local/lib/ruby1.9/gems/1.9.1/gems/rack-1.0.0/lib/rack/builder.rb:46:in `map'
from /root/svn_local_copies/OpenXDMS/trunk/lib/rack/core.rb:46:in `block in core'
from /usr/local/lib/ruby1.9/gems/1.9.1/gems/rack-1.0.0/lib/rack/builder.rb:29:in `instance_eval'
from /usr/local/lib/ruby1.9/gems/1.9.1/gems/rack-1.0.0/lib/rack/builder.rb:29:in `initialize'
from /home/me/myfile.rb:1:in `new'
...
It fails in ruby 1.8 and 1.9. Why cannot I use "do-end" syntax for a block
instead of "{ }". Of course, Proc.new does allow "do-end" syntax, so I wonder
if this issue has something to do with Rack itself.
Thanks.
--
Iñaki Baz Castillo <ibc@aliax.net>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: "run Proc.new" using "do ... end" fails ("{ }" required)
2009-10-16 17:48 "run Proc.new" using "do ... end" fails ("{ }" required) Iñaki Baz Castillo
@ 2009-10-16 18:02 ` Yehuda Katz
2009-10-16 18:15 ` Iñaki Baz Castillo
0 siblings, 1 reply; 3+ messages in thread
From: Yehuda Katz @ 2009-10-16 18:02 UTC (permalink / raw)
To: rack-devel
[-- Attachment #1: Type: text/plain, Size: 2271 bytes --]
This is normal Ruby semantics.
Consider:
method_name another_method do
end
In this case, the "do" is bound to method_name. Now consider:
method_name another_method {
}
In this case, the {} is bound to another_method. Proc.new is just a normal
method, so the above applies.
-- Yehuda
On Fri, Oct 16, 2009 at 10:48 AM, Iñaki Baz Castillo <ibc@aliax.net> wrote:
>
> Hi, the following works:
>
>
> 1 ::Rack::Builder.new do
> 2 map "/" do
> 3 run Proc.new { |env|
> 4 [ 404, {"Content-Type" => "text/plain"}),
> [""] ]
> 5 }
> 6 end
> 7 end
>
>
> but the following gives an error:
>
> 1 ::Rack::Builder.new do
> 2 map "/" do
> 3 run Proc.new do |env|
> 4 [ 404, {"Content-Type" => "text/plain"}),
> [""] ]
> 5 end
> 6 end
> 7 end
>
> /home/me/myfile.rb:3:in `new': tried to create Proc object without a block
> (ArgumentError)
> from /home/me/myfile.rb:3:in `block (2 levels) in core'
> from
> /usr/local/lib/ruby1.9/gems/1.9.1/gems/rack-1.0.0/lib/rack/builder.rb:29:in
> `instance_eval'
> from
> /usr/local/lib/ruby1.9/gems/1.9.1/gems/rack-1.0.0/lib/rack/builder.rb:29:in
> `initialize'
> from
> /usr/local/lib/ruby1.9/gems/1.9.1/gems/rack-1.0.0/lib/rack/builder.rb:46:in
> `new'
> from
> /usr/local/lib/ruby1.9/gems/1.9.1/gems/rack-1.0.0/lib/rack/builder.rb:46:in
> `map'
> from /root/svn_local_copies/OpenXDMS/trunk/lib/rack/core.rb:46:in `block in
> core'
> from
> /usr/local/lib/ruby1.9/gems/1.9.1/gems/rack-1.0.0/lib/rack/builder.rb:29:in
> `instance_eval'
> from
> /usr/local/lib/ruby1.9/gems/1.9.1/gems/rack-1.0.0/lib/rack/builder.rb:29:in
> `initialize'
> from /home/me/myfile.rb:1:in `new'
> ...
>
>
> It fails in ruby 1.8 and 1.9. Why cannot I use "do-end" syntax for a block
> instead of "{ }". Of course, Proc.new does allow "do-end" syntax, so I
> wonder
> if this issue has something to do with Rack itself.
>
>
> Thanks.
>
>
> --
> Iñaki Baz Castillo <ibc@aliax.net>
>
--
Yehuda Katz
Developer | Engine Yard
(ph) 718.877.1325
[-- Attachment #2: Type: text/html, Size: 3001 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: "run Proc.new" using "do ... end" fails ("{ }" required)
2009-10-16 18:02 ` Yehuda Katz
@ 2009-10-16 18:15 ` Iñaki Baz Castillo
0 siblings, 0 replies; 3+ messages in thread
From: Iñaki Baz Castillo @ 2009-10-16 18:15 UTC (permalink / raw)
To: rack-devel
El Viernes, 16 de Octubre de 2009, Yehuda Katz escribió:
> This is normal Ruby semantics.
> Consider:
>
> method_name another_method do
>
> end
>
> In this case, the "do" is bound to method_name. Now consider:
>
> method_name another_method {
>
> }
>
> In this case, the {} is bound to another_method. Proc.new is just a normal
> method, so the above applies.
Great explanation. Thanks a lot.
--
Iñaki Baz Castillo <ibc@aliax.net>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-10-16 18:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-16 17:48 "run Proc.new" using "do ... end" fails ("{ }" required) Iñaki Baz Castillo
2009-10-16 18:02 ` Yehuda Katz
2009-10-16 18:15 ` Iñaki Baz Castillo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).