© Carleton DiLeo 2019
C. DiLeoClean Rubyhttps://doi.org/10.1007/978-1-4842-5546-9_3

3. Creating Quality Methods

Carleton DiLeo1 
(1)
Boulder, CO, USA
 

A method is the smallest block of code in an application. Methods can be reused, which helps prevent duplication. A method hides the details of an operation, so refactoring will not affect the calling code. This takes careful planning to achieve. In this chapter, we will discuss different techniques used to create quality methods: parameters, return values, guard clauses, length, comments, and nesting.

Parameters

Without parameters, there would be no way to manipulate method outcome. Parameters make methods flexible, which creates opportunities for reuse and helps prevent code duplication. Instead of copying ...

Get Clean Ruby: A Guide to Crafting Better Code for Rubyists 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.