Is there a way to simplify the following code?
filenames is a list of filenames (strings), e.g. ["foo.txt", "bar.c", "baz.yaml"]
filenames.map { |f| File.size(f) }
Is there any way to turn "File.size" into a proc or block? For methods on existing objects, I can do &:method
. Is there something analogous for module level methods?
Stdlib's
Pathname
provides a more object oriented approach to files and directories. Maybe there's a way to refactor yourfilelist
, e.g. instead of:you would use:
You can use Object#method(method_name):