Skip to content

Instantly share code, notes, and snippets.

@dstrelau
Created December 2, 2008 16:45
Show Gist options
  • Save dstrelau/31165 to your computer and use it in GitHub Desktop.
Save dstrelau/31165 to your computer and use it in GitHub Desktop.
# module: source
class Source < Thor
class Clean < Thor
desc "whitespace", "Clean trailing whitespace."
method_options :extension => :optional
def whitespace
Dir.glob("./**/*#{options[:extension]}").each do |file|
next unless File.file?(file)
cleaned = []
File.open(file) do |f|
f.readlines.inject(cleaned) do |cleaned, line|
cleaned << if line =~ /^\s+$/ then "\n" else line.sub(/[ ]+$/, '') end
end
end
File.open(file, 'w') {|f| f.write(cleaned) }
end
end # def whitespace
end # class Clean
end # class Source
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment