Join Kevin Skoglund for an in-depth discussion in this video Return value, part of Ruby Essential Training.
In last movie, we saw how we could use arguments to get values into our methods…so that we could use them.…What about getting values back out of the methods?…For that, we need to take a look at the method Return Value.…In my ruby_sandbox, you'll see I have a new file now called return_value.rb.…If we open it up, you'll see this is basically the same file we've been working…with, just pared down a little bit.…Now we've already been working with return values without really knowing it.…Now, we have already seen return values when we were working in irb.…Let's go back and just open up an irb session to remind ourselves.…I'll just open one without simple-prompt.…
If we have 1+1, we're not doing a puts, right?…We're getting the return value of 2.…If I do puts 1 +1, then we are outputting 2, and our return value is nil.…And we talked about that puts always has return value of nil.…So that was true in irb.…It's also true back here in our method definitions.…So when we call welcome, it runs puts, which outputs what we asked it to, and…
- 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?
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.