Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Teaching Ruby to Count

Teaching Ruby to Count

Ruby has some of the best tooling in the business for working with iteration and data series. By leveraging its full power, you can build delightful interfaces for your objects.

In this case-study based presentation, we’ll explore a variety of problems such as composing Enumerable methods, generating a series of custom objects, and how to provide a clean interface for a collection with multiple valid traversal orders. Beyond just the beloved Enumerable module, this talk will take you into the world of Enumerators and Ranges and equip you to write objects that bring joy to your teammates.

Originally given at RubyConf Mini 2022. Video can be viewed at https://www.youtube.com/watch?v=PHMOsTK1jSE

Joël Quenneville

November 17, 2022
Tweet

More Decks by Joël Quenneville

Other Decks in Technology

Transcript

  1. $result = []; for ($i=0; $i<$array.length; $i++) { if ($array[$i]

    % 2 == 0) { $result[] = $array[$i]; } } return $result;
  2. march = Date.new(2022, 3) sept = Date.new(2022, 9) (march..sept).each do

    |date| # ... end # March 1, March 2, March 3, ...
  3. march = Month.from_parts(2022, 3) sept = Month.from_parts(2022, 9) (march..sept).each do

    |month| # ... end # March 2022, April 2022, May 2022, ...
  4. monte_cristo.find do |line| line.include? "Villefort" end # => "“Could you

    ever have credited such a thing, my dear Danglars?” asked M. Morrel, as, on his return to the port for the purpose of gleaning fresh tidings of Dantès, from M. de Villefort, the assistant procureur, he overtook his supercargo and Caderousse."