Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > [Q] is it impossible to pass block into proc object?

Reply
Thread Tools

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

 
 
makoto kuwata
Guest
Posts: n/a
 
      04-22-2012
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
 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      04-22-2012
On 04/22/2012 05:43 AM, makoto kuwata wrote:
> 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?


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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
impossible to delete file because it is impossible to take ownership Devvie Nuis Computer Support 21 04-20-2009 02:07 AM
A cleaner way to pass a block or proc Tristin Davis Ruby 14 06-26-2008 09:36 PM
"break" from a block and a proc object used in block position Wolfgang Nádasi-Donner Ruby 0 05-31-2007 06:05 PM
Making the simple impossible and the impossible unthinkable... xfx.publishing@gmail.com Perl Misc 5 06-30-2006 11:50 AM
Convert VB.NET to TSQL PROC & Reference a Proc from another Proc David Lozzi ASP .Net 3 06-01-2005 06:35 PM



Advertisments