by mmastrac · 10y ago · 0 comments
On top of that, consider making every bit of clever code a reusable library snippet instead. If it becomes part of the vocabulary of your codebase it'll be easier for others to understand it by looking at call sites.
eg:
# Capitalize the first letter of every word
@sentence = @sentence.split(' ').map!{|x| x = x[0..0].upcase << x[1..-1]}.join(' ')Could this be done with one gsub regex?
why use "x = x[0..0].upcase << x[1..-1]", instead of "x[0]=x[0].upcase; x" ?
And why not use the already-written "titleize" function, which capitalizes the first letter of each word?
Frankly, I think your darling needs to be put out of its misery. :-)
Which is a function provided by ActiveSupport. It's not part of Ruby itself.