-
Implement a Class, name it RecentFiles
-
You can start implementing your class from 2nd line onwards.
-
You can run the test code, which will test your code using the following command:
rspec file_name.rb
-
You can replace the
file_name.rb
with your actual file which you are working with. -
If you get any errors such as
rspec not found
etc, please do:sudo gem install rspec
-
The class should be able to handle the following scenarios:
- Output a list of most recent accessed files.
- If a file with same name is accessed multiple times, your list should include or consider it only once.
- Your list should keep track of only most recent 5 files.
- The most recent file should be on top of the list OR first element in your list
- Here's how the code API should look like:
class RecentFiles
# your code here
end
recent = RecentFiles.new([])
or
recent = RecentFiles.new(['file1', 'file2'])
recent.add('filename') # this file should go to the top of the list
recent.files # this should give you ['filename', 'file1', 'file2']