Talking about which, explain to me why sub does two passes.
Okay, Ruby ripped of some ideas from Perl, including regex. GJ! Unfortunately, it didn't include the rather terse s/// syntacitic sugar. Fine, it's not pretty, but I can live with that. However:
i = '\\'
puts i.sub(/\\/, '\\')
The result is a single backslash. What about this:
i = '\\'
puts i.sub(/\\/, '\\\\')
Should give two, right? No, it gives one. If I want two, I need to use either '\\\\\\' or '\\\\\\\\'. Or I can use:
i = '\\'
puts i.sub(/\\/) { '\\\\' }
Least surprise? I think not.