Join Kevin Skoglund for an in-depth discussion in this video Restaurant class, part of Ruby Essential Training.
- View Offline
- Exercise Files
So far we sketched out our guide class, and we have been able to instantiate it…and launch it, but it doesn't actually do much.…So we need to start going back into those methods and fleshing them out.…And I want to start with the initialize method.…if you all remember, the initialize method in the guide takes a path that we…sent them into it, and tries to find a file located at that path.…If it can't find it, it tries to create it.…Now we could just put that functionality right there in the initialize method.…But that's not the best option.…It's not as object-oriented as it could be.…Instead, it's going to be much better to have a restaurant class and put all of…the functionality of dealing with that data file in the restaurant class.…
So I have gone ahead and started the restaurant class.…Let's open that up.…It's in restaurant.rb in the lib folder, and it is just a real simple class definition.…Notice I have got a class variable here for file path, so we don't need an…instance to have the file path, and I'll start it out equal to nil.…
- 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.