You could record a macro that selects the current line (apple-L) then invokes the command.
Apple-SHIFT-L, sorry!
Also, the line of Ruby code I posted needs to be changed to
line = line.gsub(/([\$\\`])/){"\\#$1"}
otherwise it gives an error when
a) the cursor is already at the end of the initial whitespace on the line, and
b) the line contains a special character ($, \, or `).
Robin