From: George Ogata Date: 2004-09-27T15:04:28+09:00 Subject: Re: Object#send and blocks/procs "Mehr, Assaph (Assaph)" writes: > > 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".send(:gsub, /./) # how do I pass prc as the block to > gsub? > > Solution: > > puts "aaa".send(:gsub, /./) { |x| prc[x] } puts 'aaa'.send(:gsub, /./, &prc)