r/ruby • • Jul 20 '16

New Features in Ruby 2.4

http://blog.blockscore.com/new-features-in-ruby-2-4/
145 Upvotes

25 comments sorted by

View all comments

2

u/ilmari2k Jul 20 '16

The regexp match might yield some performance benefits if done multiple times inside a large loop for example. Is it find/replaceable?

2

u/berkes Jul 21 '16

I'd say no.

#match? is for when you only care that there is a match, #match for when you actually want to do something with it. Which is hard to detect in a find-replace-batch because the MatchData might be used elsewhere, without an obvious assigment or passing around of variables.

They have different usecases. And unless you are 100% sure all your usage of #match fit in the "only check if it is matching, never using the matched data" you cannot do a search-replace.