/enumerable-proxy

A pattern for simple block-free ruby enumeration

Primary LanguageRubyMIT LicenseMIT

Enumerable Proxy

Background

See here and here

Installation

sudo gem install enumerable-proxy

Usage


require 'enumerable_proxy'

[1, 2, 3].proxy(:map) == 2 #=> [false, true, false]

[1, 2, 3].p(:map).to_s #=> ['1', '2', '3']

[1, 2, 3].pmap * 10 #=> [10, 20, 30]

#peach, pmap, pselect, preject, pall?, pany?, pdetect are all added to Array.

To get even more succinct, require enumerable_proxy/array_extensions and
it’ll alias_method_chain Array#map, each, etc so if they are called with no block,
they will return a proxy for their method.


require 'enumerable_proxy/array_extensions'

[1, 2, 3].map.to_s #=> ['1', '2', '3']
[1, 2, 3].map + 2 #=> [3, 4, 5]

(0..10).to_a.select < 5 #=> [0, 1, 2, 3, 4]