On Wed, Oct 17, 2012 at 1:58 PM, Joel Pearson <[email protected]> wrote: >> irb(main):010:0> s.gsub /\A#|#\z/, '' >> => "aaaa\n#bbb#cc#\n" >> irb(main):011:0> s == s.gsub(/\A#|#\z/, '') >> => true
> This looks like the best solution. One should use gsub! though if the old String does not need to be retained - that saves memory because the String is changed in place. If the old String should be retained this approach might actually be more efficient since AFAIK both strings share the char buffer if I am not mistaken: s = s[/^#?(.*?)#?\z/, 1] But this is micro optimizing already so better pick what suits you best. 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
