Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Proc in ruby 1.8.6 and 1.8.7
Robert Pankowecki
6/2/2009 4:39:00 PM
In Ruby 1.8.7 it is possible to do such thing:
pr = Proc.new do |arg, &block|
block.call
end
pr.call(123) do puts "xyz" end
xyz
=> nil
When calling proc another block can be given as parameter.
Is there any way to do it in Ruby 1.8.6 ?
Not working:
irb(main):001:0> aba = Proc.new do |arg, &block|
irb(main):002:1* end
SyntaxError: compile error
(irb):1: syntax error, unexpected tAMPER, expecting '|'
aba = Proc.new do |arg, &block|
^
from (irb):2
==
Not working:
irb(main):003:0> pr = Proc.new do |arg, block|
irb(main):004:1* block.call
irb(main):005:1> end
=> #<Proc:0xb7d2d630@(irb):3>
irb(main):006:0> pr.call(123) do puts "xyz" end
NoMethodError: undefined method `call' for nil:NilClass
from (irb):4
from (irb):6:in `call'
from (irb):6
irb(main):007:0>
==
Working, but i want to avoid this solution:
irb(main):007:0> pr.call 123, Proc.new{puts "xyz"}
xyz
=> nil
irb(main):008:0>
I hope you people know some cool workaround.
My application is currently running on Ruby 1.8.7 but i would like to
use REE instead and right now this is the only issue that stops me from
it.
--
Posted via
http://www.ruby-...
.
1 Answer
Brian Candler
6/2/2009 5:13:00 PM
0
Robert Pankowecki wrote:
> Working, but i want to avoid this solution:
>
> irb(main):007:0> pr.call 123, Proc.new{puts "xyz"}
Yes, that's what you need - to pass the block as an explicit argument.
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Proc in ruby 1.8.6 and 1.8.7
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password