What is the fastest, most optimized, one-liner way to get an array of the directories (excluding files) in Ruby?
How about including files?
Dir.glob("**/*/") # for directories Dir.glob("**/*") # for all files
Instead of Dir.glob(foo) you can also write Dir[foo] (however Dir.glob can also take a block, in which case it will yield each path instead of creating an array).
Dir.glob(foo)
Dir[foo]
Dir.glob
Ruby Glob Docs
2.1m questions
2.1m answers
60 comments
57.0k users