I love that when Ruby surprises me, it’s never the kind of surprise like, “Huh? Why does it do that?” - but instead it’s always, “Oh, wow, OF COURSE that makes perfect sense, I just never thought of it like that!”

Newest case of that: passing blocks to gsub

I had always done gsub using a string as the replacement:

> s = ‘pretty little ponies’
> s.gsub(/[^aeiou]/, ‘_’)
=> “__e_____i___e__o_ie_”

But the book Ruby for Rails had an example of passing a block into gsub:

> s.gsub(/[^aeiou]/) {|c| c.upcase}
=> “PReTTY LiTTLe PoNieS”

Beautiful