Is there a straight forward way to modify a Rake task to run some bit of code before running the existing task? I'm looking for something equivalent to enhance, that runs at the beginning rather than the end of the task.
Rake::Task['lame'].enhance(['i_run_afterwards_ha_ha'])
Or you could use the rake-hooks gem to do before and after hooks:
https://github.com/guillermo/rake-hooks
You can use the dependency of Rake task to do that, and the fact that Rake allows you to redefine existing task.
Rakefile
As result