Groups
Groups
Sign in
Groups
Groups
comp.lang.ruby
Conversations
About
Send feedback
Help
Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss
Learn more
[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 PM
4/21/12
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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 AM
4/22/12
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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