Store the Last Five Lines in an Array in Ruby
In this guide, you will learn how to retrieve some content from a file and store it in an array for later use.
Guide Tasks
- Read Tutorial
- Complete the Exercise
Summary
Build a method that finds and stores content in an array.
Exercise Description
Define a method that can retrieve the last 5 lines from a file and put them in an array.
Example Data
([ "Satisfied with Smile Dental? Review us on Yelp!", "How was your service at ZenSpa?", "Thanks for visiting! Here’s a link to submit your review", "Please share your experience with us!", "Let’s be friends—Like and Review us on Facebook!" ])
Real World Usage
Once you understand how to find and store information in an array, it can then be used for other implementations. This is a fairly simple concept to grasp and can be used for various situations.