On Thu, Jul 19, 2012 at 8:03 PM, Albert Schlef <[email protected]> wrote:
> I finally solved my problem by doing:
>
> "a b c".sub("b") { "believe\\+me" }
>
> But I wonder if this is the "best" Ruby has to offer for my very humble
> demands.
It's usually slower. The intended use of the block form is where
calculations need to be done for each replacement. That's not the
case here. Please see Brian's excellent explanation of how it's done
without block and why so many backslashes are needed.
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
-- You received this message because you are subscribed to the Google Groups
ruby-talk-google group. To post to this group, send email to
[email protected]. To unsubscribe from this group, send email
to [email protected]. For more options, visit this
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en