Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Q] is it impossible to pass block into proc object?

32 views
Skip to first unread message

makoto kuwata

unread,
Apr 21, 2012, 11:43:39 PM4/21/12
to
Hi,

I have a question about proc object and block.

I tried the following code:

pr = proc do
yield "hom"
end

pr.call do |arg|
p arg
end

What I expected is:

$ ruby homhom.rb
hom

But I got:

$ ruby homhom.rb
homhom.rb:2:in `block in <main>': no block given (yield)
(LocalJumpError)
from homhom.rb:5:in `call'
from homhom.rb:5:in `<main>'
$ ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin10.8.0]

Is it impossible to pass block to proc object?

--
makoto kuwata

Robert Klemme

unread,
Apr 22, 2012, 8:33:38 AM4/22/12
to
The only way I am aware of ATM is explicit:

irb(main):003:0> pr = lambda {|bl| bl.call "hom" }
=> #<Proc:0x829cd74@(irb):3 (lambda)>
irb(main):004:0> pr.call lambda {|x| p x}
"hom"
=> "hom"

Kind regards

robert
0 new messages