A pattern for simple block-free ruby enumeration
Ruby
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.document
.gitignore
LICENSE
README.textile
Rakefile
VERSION
enumerable-proxy.gemspec

README.textile

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]