s.split.map{|w|w.capitalize}.join(' ')
each
doesn't chaineach
returns the original collectionmap
returns a new collectionmap
and chainings.split.map{|w|w.capitalize}.join(' ')
each
and !
s.split.each{|w|w.capitalize!}.join(' ')
each
and an accumulatorcapitalized = []
s.split.each{|w|
capitalized << w.capitalize
}
capitalized.join(' ')
s # "foo_bar"
.split("_") # ["foo", "bar"]
.map {|w| # "foo", then "bar"
w.capitalize # "Foo", then "Bar"
} # ["Foo", "Bar"]
.join(" ") # "Foo Bar"
/