Created
October 4, 2011 18:42
-
-
Save rdammkoehler/1262435 to your computer and use it in GitHub Desktop.
Example of using a variable for a regular expression.
This file contains hidden or 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
| class Filter | |
| def initialize directory | |
| @directory = directory | |
| end | |
| def filter regex=".*" | |
| entries = Dir.entries @directory | |
| entries.reject { |e| !( e =~ /#{regex}/ ) } | |
| end | |
| end | |
| filter = Filter.new ARGV.shift | |
| matches = filter.filter ARGV.shift | |
| puts matches |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment