TIL on
Ruby’s gsub accepts a block via &: shorthand syntax
You may already know you can pass a block to gsub like this:
"the html spec and some css tricks".gsub(/\b(html|css)\b/) { it.upcase }
# => "the HTML spec and some CSS tricks"
But you can make this even simpler by using the &: shorthand syntax:
"the html spec and some css tricks".gsub(/\b(html|css)\b/, &:upcase)
# => "the HTML spec and some CSS tricks"
Isn’t Ruby just beautiful?