Skip to content

Instantly share code, notes, and snippets.

@rdammkoehler
Created October 4, 2011 18:42
Show Gist options
  • Select an option

  • Save rdammkoehler/1262435 to your computer and use it in GitHub Desktop.

Select an option

Save rdammkoehler/1262435 to your computer and use it in GitHub Desktop.
Example of using a variable for a regular expression.
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