The only other one I saw posted missed parts of the specified subfolders. So here goes:
begin
require 'flay'
desc "Run duplicate code analyzer"
task :flay do
output = `flay #{FileList["lib/**/*.rb", "app/**/*.rb"].join(' ')}`
fail "Error #{$?}: #{output}" unless $? == 0
puts output
end
rescue LoadError => exception
warn "Could not load flay - it might not be installed."
end