10 Pines Blog

Collection Filters in Ruby

oop ruby

Note: acknowledgements (and thanks!) to Máximo Prieto (our OOP guru) who had this idea and he implemented it on Smalltalk.

The problem

We want to have a collection that filters its elements as we add them using a given condition. For instance, we can have an Array that only allows even numbers.

First, and important, is to understand what a filter is. “filter” is a very overloaded word, and sometimes used in a technical way. Let’s say that a filter is someone with the single responsibility of deciding if something has to pass over or not.

14 Jul 2016

Ruby On Pains

ruby rails best practices

Have you ever heard about the Rails way? I would like to introduce some pains that I’ve seen and keep seeing in all the Rails projects due to the Rails way

25 Nov 2015

Symbols: the new return codes? (Pt. 2)

ruby nil closures symbols exceptions

Flow control with exceptions and closures

In this previous post we’ve considered the benefits and inconveniences of using nil and symbols as return values in a method. Now we’ll evaluate the possibility of throwing an exception, and yet another alternative: using a closure.

29 Sep 2014

Symbols: the new return codes?

ruby nil closures symbols exceptions

Recently I’ve read a tweet from Yehuda Katz in which he suggested an interesting idea, as an alternative for using nil as a result from a method: to use a symbol instead.

Well, this post is about the reasons why I think you shouldn’t use a symbol, and why even returning nil is a preferable option.

24 Sep 2014

Rock Your Ruby: The Value of Value

ruby

Check out the Ruby Gem at GitHub

Introduction

Go ahead and ask the developer sitting next to you what is the thing that loves the most about Ruby. It should come as no surprise that simplicity, flexibility and expressiveness are the main reasons Ruby junkies just can’t get enough of it.

In Matz own words, seems like the ‘go with the flow’ philosophy was present right from the start in the Ruby community:

{% blockquote %} “Actually, I’m trying to make Ruby natural, not simple.” {% endblockquote %}

4 Mar 2014