Join Kevin Skoglund for an in-depth discussion in this video Variable scope in methods, part of Ruby Essential Training.
Now that we have seen how to define Ruby methods, I want to take this…opportunity to take a look at variable scope.…We first talked about variable scope back when we introduced variables, and at…the time I told you that we really wouldn't be able to go into it in any kind of…depth until we had some more complex Ruby structures that we could look at and…see how variables interacted in those context.…We revisited the subject again when we got to blocks and now that we have…methods, we can see how variable scope applies to methods as well.…In my ruby_sandbox, I have now got another file called method_scopes.…Its basically the same file that we were working with, I just saved a different…copy of it, so that I could keep the work separate.…
I have also removed all the comments that we had made.…You will notice in our method definitions we are using local variables in a few…places, words, longest_word, and value.…We have also got block variables, word and memo that we are using.…We have already seen how block variables work.…
- 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.