Join Kevin Skoglund for an in-depth discussion in this video Argument default values, part of Ruby Essential Training.
In the last movie we saw how if we didn't send the same number of arguments to…our method as it was expecting, that we got an error.…In this movie we are going to see how we can use argument default values…to avoid those errors.…You will see that I have a new file on my ruby_sandbox, its argument_defaults,…and I will open it up.…It's basically the same file that we have been working with, just a little bit cleaned up.…The case that I want us to look at is how we can set a default value so that,…for example, if we called welcome, and we just called it by itself and we did…not send anything, that there would be a default behavior that would happen…instead of giving us the error.…
The way we do that is we just go ahead and make an assignment to this variable…inside the argument list.…So Hello World, for example.…Now when we call it, we don't get an error anymore, because even though we…didn't send an argument, it was satisfied because it said, ah, my argument did…get a value in the end, not one you sent to me, but one that I set myself.…
- 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
Q: You mention e-texteditor.com as a place to get a Windows "sister" version of TextMate. However, e-texteditor.com looks like a Chinese auto website. Are there any other alternatives?
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?
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.