Join Kevin Skoglund for an in-depth discussion in this video Listing restaurants, part of Ruby Essential Training.
- View Offline
- Exercise Files
Now that we have a few restaurants saved on our file, we can now write the list action.…We will actually display the restaurants that are saved, so the user can review them.…The process of starting the action is the same as we did for add. We are…going to just have list here called as a separate method and we are going to…define this method here.…We also created a stub for saved_ restaurants over here as a class method on…restaurant, back at the very beginning.…That's what we want to flush out, right?…That's going to pull up an array of all those saved restaurants.…Then the list can actually go about listing them, right?…So, let's have the list action. We'll just copy this first line from adds, all right.…
So, it's going to be Listing restaurants, here we go.…So, that will be the title here of the page, and then we know that we want to do restaurants.…That's going to be equal to ask the Restaurant class to return…the saved_restaurants.…And that will give us an array that we can go on to display.…
- Using Ruby in the Interactive Ruby Shell and in standalone scripts
- Learning to write custom code blocks to find, merge, and sort
- Using modules for namespacing or as mix-ins
- Reading from and writing to files
- Creating a full Ruby project from start to finish
Skill Level Beginner
1. Getting Started with Ruby
2. Ruby Object Types
3. Control Structures
4. Code Blocks
8. Working with Files
9. Ruby Project: Creating the Food Finder
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.