Enumerable: How I fell in love with Ruby

This repository contains code snippets used in my presentation on Ruby's enumerable module. Ruby code was written to run on Ruby 2.2.

Enumerable presentation on Slidedeck

Usage

To run a sample, clone the repo and install the gems:

$ git clone https://github.com/rossta/loves-enumerable.git
$ gem install

Then simply run the code with the ruby executable.

$ ruby code/pascals_triangle.rb

You'll get the most out of this repo by inspecting the source along with following the presentation.

Main Points

Use more of the Enumerable API

  • look for more direct solutions
  • read the docs

Learn how Enumerable methods are implemented

  • it’s not magic
  • implement Enumerable on your own
  • create your own extensions

Encapsulate complexity of enumerating

  • stream data to client
  • deferred data fetching

Provide Enumerators

  • for any method that returns an enumerable with a block return an enumerator when the block is missing

When to be Lazy

  • for avoiding eager evaluation
  • for filtering results over large collection

Embrace the functional flavor

  • given the same inputs, you can expect the same results
  • use Enumerables like Legos: as building blocks

Resources

Many of the ideas and examples are adapted from other great sources. Please check out the following to learn more.

General

Lazy Enumerators

Streaming

Code

Data sources

Books

  • The Well-Grounded Rubyist by David Black

Built With

Share this project:
×

Updates