Created
December 28, 2010 08:27
-
-
Save wbailey/757051 to your computer and use it in GitHub Desktop.
Using a mixin to extend the object instance with the functionality we want
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Logfiles | |
def name | |
self.sub(/\.gz$/) | |
end | |
def skip? | |
!(@options[:unzip] && self.gzip?) | |
end | |
def gzip? | |
self.match(/\.gz$/) | |
end | |
def cleanup | |
system "gzip #{self.name}" if self.gzip? | |
end | |
end | |
Dir['*'].each do |file| | |
file.extend Logfiles | |
next if file.skip? | |
IO.foreach(file.name) do |line| | |
#... | |
end | |
file.cleanup | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I like the riff generalization