M
Mehr, Assaph (Assaph)
Hi Guys,
I started to write this email as a question, but figured the answer in
the middle...
So now I want to know if there's any problem with the code below, if
there is any performance hit or if there's a simpler way to turn Procs
back into blocks.
The question is how do I #send a method to an object with an attached
proc (not block)? The simplest way to reproduce is:
prc = lambda{ |a| a.upcase }
puts "aaa".sendgsub, /./) # how do I pass prc as the block to
gsub?
Solution:
puts "aaa".sendgsub, /./) { |x| prc[x] }
i.e. I have wrapped my Proc object within a block. Some interspersing of
'*' may be required for multiple params, as Markus pointed out in
another thread.
Cheers,
Assaph
I started to write this email as a question, but figured the answer in
the middle...
So now I want to know if there's any problem with the code below, if
there is any performance hit or if there's a simpler way to turn Procs
back into blocks.
The question is how do I #send a method to an object with an attached
proc (not block)? The simplest way to reproduce is:
prc = lambda{ |a| a.upcase }
puts "aaa".sendgsub, /./) # how do I pass prc as the block to
gsub?
Solution:
puts "aaa".sendgsub, /./) { |x| prc[x] }
i.e. I have wrapped my Proc object within a block. Some interspersing of
'*' may be required for multiple params, as Markus pointed out in
another thread.
Cheers,
Assaph