Build an Array Method that Returns a List of Filenames for Specific File Types


Parsing file types can be a complex process. However, by leveraging the grep method you can leverage regular expressions to quickly return a full list of all of the file types that you’re searching for.


Build a method that searches for specific file types.

Exercise File

Code File

Exercise Description

Add a method to the Array class that can look through an array of file names and return a filtered array with the file names for the file type searched for.


file_names = %w{file1.rb file2.html file3.rb file4.rb file5.js}
file_names.file_selector 'rb' # => ['file1', 'file3', 'file4']

Real World Usage

Ruby provides developers a number of options when it comes to implementing solutions. As a dev, one of the daily tasks that you’ll have is to work through various solutions to find the one that works the best for your particular program. There were multiple ways to solve this exercise and being able to experiment with what makes one solution a better fit than another is important. Additionally, if you implemented the solution that I utilized, you will have also worked with: regular expressions and Unix command tools.


Can be found on the solutions branch on github.


Please enter your comment!
Please enter your name here