Methods and Madness No. 1

I’m going to post this every week to improve my Ruby chops.

I subscribe to Ruby Methods Daily, where they send out a couple of Ruby methods to my inbox and I get to read over them. Reading with code is NEVER enough, though. So I’ve tried to use those methods for *something* each time I read them. Even if I just make a simple method or class to see how I would apply it in practical terms.

Already this has helped me come up with more clever (and good) solutions for the code challenges at Codewars. So then …why not publish those little practice runs right here for others interested in improvement?

Thus was born Methods and Madness. The format from here on out will be a simple list of the methods learned along with a very basic (and practical) example of it’s usage. When I say practical I mean an example used within a meaningful context in a way that it’s typically employed in real code.

Methods

.tap  is what I’ve heard described as a “convenience” method. It doesn’t do anything particularly special except make your code more readable and concise.

Rubydocs | Stackexchange

.one?  is part of the Enumerable object, something I’m coming to know is one of Ruby’s most powerful libraries. This method makes it easier to search a set of data by returning true for the set if only one element evaluates to true.

Rubydocs

Leave a Reply

Your email address will not be published. Required fields are marked *