Join Kevin Skoglund for an in-depth discussion in this video Inject, part of Ruby Essential Training.
In this movie, we're going to take a look at inject, which is another Ruby…method that makes good use of code blocks.…Well, it may help to know that inject is an accumulator.…So that's what it's going to do.…It's going to accumulate for us.…So when you see the word inject immediately think accumulate, and if we're…going to accumulate values then we're going to need a place to accumulate…them, right, a variable.…And so we'll have a block variable that will do our accumulating for us.…And by convention, we call that block variable, memo.…You can call it something else if you want, but most programmers are going to…use memo and I suggest you do too, just to remind yourself that's what it is.…
That this is the accumulator where we're accumulating our values.…I think it's also helpful before we look at inject to look back at collect for a second.…We saw how we could have a range like 1 through 10 and use the collect method…with the block and we would apply that block as a transformation to each one of the elements.…
- 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.