Last active
August 29, 2015 14:07
-
-
Save mehdi-farsi/86c711bd22ff9f678bf6 to your computer and use it in GitHub Desktop.
Fetch filenames using filter and REGEX
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
# In the following example some simple default options are set. | |
class Dir | |
@list_options = { hidden_files: /^\./, visible_files: /^[^\.]/, files: // } | |
def self.list(path = '.', option = :visible_files) | |
entries(path).grep(@list_options[option]) | |
end | |
end | |
# Examples | |
Dir.list('.', :hidden_files).each { |file| print "#{file} " }; puts | |
Dir.list('.', :visible_files).each { |file| print "#{file} " }; puts | |
Dir.list('.', :files).each { |file| print "#{file} " }; puts | |
# OUTPUT | |
$> ruby dir.rb | |
. .. .DS_Store | |
dir.rb test.json | |
. .. .DS_Store dir.rb test.json | |
$> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment