Properly detect end of Ruby line

(shamelessly taken from the HAML bundle)