4
Ruby Methods
Overview
By the end of this chapter, you will be able to define and call your own methods for Ruby programs; set parameters for methods in Ruby; provide default values for a parameter in Ruby; implement methods in Ruby that return multiple values and write code using the built-in modules of Time and Math.
Introduction
In the previous chapter, we learned about Boolean variables, conditional expressions, and loops, including the core Ruby concepts of using blocks. We will now zoom out a little in the Ruby world and learn about methods. In fact, we've been using methods in the previous chapters, and we will look at them in more depth now.
Methods are foundational units in Ruby. They allow you to wrap code in chunks that can ...
Get The Ruby Workshop now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.