Ruby, PHP and the Array Map method

Due to my work and my academia commitments I find myself very often switching from Ruby to PHP and back again. This is making me more and more accustomed to the substantial differences between these two languages.

Among these differences the handling of collections is perhaps one of the biggest I found till now.

For example in Ruby there is a module (i.e. an object) called Enumerable that exposes a lot of useful helpers and utilities to work with collections (i.e. objects).

One of these utilities is map. The concepts underlined are pretty much the same across languages and are summarized here.

While working on a collection of objects, in particular a Nokogiri::XML::NodeSet, I recently had the need to extend the map behavior to get a collection of non duplicated Nokogiri::XML::Node elements.

Continue reading “Ruby, PHP and the Array Map method”