3 ms·
Huh, I've been doing Ruby since 2008 and I've never seen a block passed to gsub/gsub!. Neat! That said, a block isn't necessary here and the one-liner can be
by brobinson 11y ago
Huh, I've been doing Ruby since 2008 and I've never seen a block passed to gsub/gsub!. Neat!
That said, a block isn't necessary here and the one-liner can be even shorter:
@sentence.gsub!(/\b\w/, &:upcase)
&: call syntax is actually a little faster post 1.9, too.