Reusing the Wheel

By Tony Vincent T.Y

Talk Abstract

This talk demonstrates with examples how to write better Ruby code using some lesser known, underused ruby/rails methods & abstractions. Don’t miss this talk if you want to learn about some simple yet powerful methods like ‘enum#flat_map’ & ‘object#tap’ that can help you code like a pro using Ruby

Talk Description

I couldn’t help but notice how cool Object#tap is to get rid of the temporary variables in my code and Array#bsearch is 3 times faster than find when working on large arrays. So I started looking for other cool methods like those and found quite a few of them. But sadly, whenever I talk about these methods, most of my fellow devs don’t even know they exist!

This talk discusses these methods( around 25 to 30 ) with example snippets that are classified into the following major groups.

  1. Ruby Enumerable
  2. Ruby Date Time
  3. Number and string formatting
  4. Rails specific
  5. Active Record
  6. Others

Apart from discussing lesser known useful methods, this talk also tries to demonstrate the lesser known use cases of popular methods like Array#count . For example, passing a block to count like this

numbers = [1,2,3,4,5]

numbers.count(&:even?)

=> 2

Notes

I have been writing Ruby code for the past 2 and half years for a living. This talk is inspired by what I learned from my efforts to write clean, maintainable ruby code and I hope this talk will help my fellow developers to ship better code and to stop reinventing the wheel all over again