# Enumerable-extra 0.1.0

**URL:** <https://www.ruby-forum.com/t/enumerable-extra-0-1-0/167986>\
**Category:** Ruby\
**Created:** [May 14, 2009, 6:09pm UTC](https://www.ruby-forum.com/t/enumerable-extra-0-1-0/167986 "2009-05-14T18:09:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [May 14, 2009, 6:09pm UTC](https://www.ruby-forum.com/t/enumerable-extra-0-1-0/167986/1 "2009-05-14T18:09:21Z")

</div>

Hi,

Convinced that Symbol#to\_proc is mostly a solution in search of a  
problem,  
I’ve released enumerable-extra 0.1.0.

= What is it?

The enumerable-extra library overrides Enumerable#map, Array#map and  
Array#map to accept a method, with optional arguments, that are  
performed on  
every element of the list.

For example, instead of this:

array.map{ |e| e.capitalize }

You can do this:

array.map(:capitalize) # Capitalize every element

You can also mix and match:

array.map(:capitalize){ |e| e + ‘x’ } # Add ‘x’ after capitalizing every  
element

= Why is it better than Symbol#to\_proc ?

First, it doesn’t require additional notation, i.e. no “&”, no “its”, no  
“self” - just a method name. In my opinion, that makes the syntax  
cleaner.  
Second, Symbol#to\_proc is slow.

= How do I get it?

gem install enumerable-extra

= Caveat

This is for Ruby 1.8.x only.

Enjoy!

Dan

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [May 14, 2009, 7:31pm UTC](https://www.ruby-forum.com/t/enumerable-extra-0-1-0/167986/2 "2009-05-14T19:31:41Z")

</div>

Would this be usable with a RoR app?

I am not certain if RoR core needs Symbol#to\_proc … but, it would be  
nice  
to use enumerable-extra in my Ruby coding in RoR. I am just iffy about  
trying it cause I am not certain if I would break my RoR app because I  
installed the gem and the gem overirides Enumberable#map and so forth.

Thanks 🙂

Sorry if it seems like a newb question, but I am learning both Ruby and  
RoR  
at the same time – so, in a sense I am a newb 😛

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [May 14, 2009, 7:40pm UTC](https://www.ruby-forum.com/t/enumerable-extra-0-1-0/167986/3 "2009-05-14T19:40:32Z")

</div>

On May 14, 11:30 am, Joshua C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> at the same time – so, in a sense I am a newb 😛  
> It might, I haven’t tried. It might depend on the order of your  
> require statements, too, because I haven’t looked at their  
> implementation.

The best way to find out is to run your tests. I’m curious about the  
results myself.

Note that, with no arguments it works the same as the standard MRI  
version, so you can still do this:

array.map{ |e| e.capitalize }

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [May 15, 2009, 3:56pm UTC](https://www.ruby-forum.com/t/enumerable-extra-0-1-0/167986/4 "2009-05-15T15:56:08Z")

</div>

On May 15, 1:47 am, Martin DeMello [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Thu, May 14, 2009 at 9:38 PM, Daniel B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > = Why is it better than Symbol#to\_proc ?
> 
> > First, it doesn’t require additional notation, i.e. no “&”, no “its”, no  
> > “self” - just a method name. In my opinion, that makes the syntax cleaner.  
> > Second, Symbol#to\_proc is slow.
> 
> This looks very nice! What would it take to port to ruby 1.9?

I’m not sure. I declared that it was for 1.8.x only because I hadn’t  
tested it with 1.9.x and I wasn’t sure if it would break its builtin  
Symbol#to\_proc support, or what would happen.

I’ll do some testing later this week with 1.9.x and see what happens.

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [May 15, 2009, 9:47am UTC](https://www.ruby-forum.com/t/enumerable-extra-0-1-0/167986/5 "2009-05-15T09:47:43Z")

</div>

On Thu, May 14, 2009 at 9:38 PM, Daniel B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> = Why is it better than Symbol#to\_proc ?
> 
> First, it doesn’t require additional notation, i.e. no “&”, no “its”, no  
> “self” - just a method name. In my opinion, that makes the syntax cleaner.  
> Second, Symbol#to\_proc is slow.

This looks very nice! What would it take to port to ruby 1.9?

martin

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [May 15, 2009, 4:37pm UTC](https://www.ruby-forum.com/t/enumerable-extra-0-1-0/167986/6 "2009-05-15T16:37:50Z")

</div>

On Thu, May 14, 2009 at 1:39 PM, Daniel B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > Thanks 🙂
> 
> Note that, with no arguments it works the same as the standard MRI  
> version, so you can still do this:
> 
> array.map{ |e| e.capitalize }

There SHOULDN’T be a conflict since Rails/ActiveSupport doesn’t change  
the map method it only adds a to\_proc method to Symbol.

require ‘rubygems’  
require ‘activesupport’  
require ‘enumerable/extra’

p %w{a b c}.map(:upcase)  
p %w{a b c}.map(&:upcase) # =\>  
p %w{a b c}.map(:upcase, &:downcase)

[“A”, “B”, “C”]  
[“A”, “B”, “C”]  
[“a”, “b”, “c”]

Now whether or not combining these is a good idea, I don’t know.

–  
Rick DeNatale

Blog: [http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)  
Twitter: [http://twitter.com/RickDeNatale](http://twitter.com/RickDeNatale)  
WWR: [http://www.workingwithrails.com/person/9021-rick-denatale](http://www.workingwithrails.com/person/9021-rick-denatale)  
LinkedIn: [http://www.linkedin.com/in/rickdenatale](http://www.linkedin.com/in/rickdenatale)

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [May 15, 2009, 6:01pm UTC](https://www.ruby-forum.com/t/enumerable-extra-0-1-0/167986/7 "2009-05-15T18:01:15Z")

</div>

On Fri, 15 May 2009 01:08:12 +0900  
“Daniel B.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> array.map(:capitalize){ |e| e + ‘x’ } # Add ‘x’ after capitalizing  
> every element
> 
> = Why is it better than Symbol#to\_proc ?
> 
> First, it doesn’t require additional notation, i.e. no “&”, no “its”,  
> no “self” - just a method name. In my opinion, that makes the syntax  
> cleaner. Second, Symbol#to\_proc is slow.

Sorry, but Symbol#to\_proc is actually the faster way since it was added  
into  
the core, so your statement is only true for \< 1.8.6.

Benchmark at: [http://pastr.it/15719](http://pastr.it/15719)
