Skip to content

Instantly share code, notes, and snippets.

@eterps
Created Jul 26, 2010
Embed
What would you like to do?
class DirTree < String
include Enumerable
def each
Dir.entries(self).reject{|n| %w[. ..].include? n}.each do |filename|
yield path = "#{self}/#{filename}"
DirTree.new(path).each{|n| yield n} if File.directory? path
end
end
end
class DiskUsage
def self.[](path)
DirTree.new(path).map{|n| File.lstat(n).size}.inject(0){|sum, size| sum + size}
end
end
p DiskUsage['.']
@eterps

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment