Join Kevin Skoglund for an in-depth discussion in this video Read from files, part of Ruby: Files, Formats, Templates.
- [Instructor] In this movie, we're going to learn…how to read data back from files.…We're going to learn three ways of doing it.…The first and the simplest is just to use the read method.…So again, we access our file,…notice that I'm using an r,…that puts it in read only mode.…So I can read back from the file, but I can't write to it.…I have that file instance stored in the variable file.…And I'm calling the read method on that file instance.…Read takes an argument, which is the number of characters…that we want to read back.…So read four,…will grab the first four characters out of that file.…
And then, I can read again.…Now if I call read a second time,…it doesn't go back and read…the same first four characters,…it continues reading from where it left off.…Ruby's going to keep track…of its position.…It's a lot like having a cursor…in a word processing program.…That cursor's going to move forward four spaces,…and then be waiting there…for when we read or write again.…So this allows you to just read…a few characters at a time out of a file.…
- File system basics
- Writing to and reading from files
- Renaming, deleting, and copying files
- Creating and editing directories
- Working with common data formats
- ERB templating
Skill Level Beginner
Ruby on Rails 5 Essential Trainingwith Kevin Skoglund10h 21m Beginner
1. The File System
2. Work with Files
3. Work with Directories
4. Common Data Formats
5. ERB Templating
- 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.