# Map with &:method\_name

**URL:** <https://rubytalk.org/t/map-with-method-name/47638>\
**Category:** ruby-talk\
**Created:** [10 July 2008 21:11 UTC](https://rubytalk.org/t/map-with-method-name/47638 "2008-07-10T21:11:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oliver\_Sauders](https://avatars.discourse-cdn.com/v4/letter/o/ecc23a/32.png) [@Oliver\_Sauders](https://rubytalk.org/u/Oliver_Sauders)\
**Post date:** [10 July 2008 21:11 UTC](https://rubytalk.org/t/map-with-method-name/47638/1 "2008-07-10T21:11:21Z")

</div>

I see this a lot but it doesn't work for me in IRB. Is a gem required or  
something?

> > [1,2,3].map(&:to\_s)

TypeError: wrong argument type Symbol (expected Proc)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):2

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![a11](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/a11/32/8169_2.png) [@a11](https://rubytalk.org/u/a11)\
**Post date:** [10 July 2008 21:22 UTC](https://rubytalk.org/t/map-with-method-name/47638/2 "2008-07-10T21:22:33Z")

</div>

it's rails - basically

class Symbol  
&nbsp;&nbsp;&nbsp;def to\_proc  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sym = self  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lambda{|obj| obj.send sym}  
&nbsp;&nbsp;&nbsp;end  
end

a @ [http://codeforpeople.com/](http://codeforpeople.com/)

> **···**
>
> On Jul 10, 2008, at 3:11 PM, Oliver Saunders wrote:
> 
> > I see this a lot but it doesn't work for me in IRB. Is a gem required or  
> > something?
> > 
> > > > [1,2,3].map(&:to\_s)
> > 
> > TypeError: wrong argument type Symbol (expected Proc)  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):2
> 
> --  
> we can deny everything, except that we have the possibility of being better. simply reflect on that.  
> h.h. the 14th dalai lama

---

<div class="post-metadata">

**Author:** ![Rick\_DeNatale1](https://avatars.discourse-cdn.com/v4/letter/r/bbce88/32.png) [@Rick\_DeNatale1](https://rubytalk.org/u/Rick_DeNatale1)\
**Post date:** [10 July 2008 22:36 UTC](https://rubytalk.org/t/map-with-method-name/47638/3 "2008-07-10T22:36:56Z")

</div>

And it's been picked up in Ruby 1.9, and maybe 1.8.7 as well since the  
current draft of the Pickaxe 3rd ed doesn't label it as 1.9 only.

> **···**
>
> On Thu, Jul 10, 2008 at 5:22 PM, ara.t.howard \<ara.t.howard@gmail.com\> wrote:
> 
> > On Jul 10, 2008, at 3:11 PM, Oliver Saunders wrote:
> > 
> > I see this a lot but it doesn't work for me in IRB. Is a gem required or
> > 
> > > something?
> > > 
> > > [1,2,3].map(&:to\_s)
> > > 
> > > > > 
> > > > 
> > > > TypeError: wrong argument type Symbol (expected Proc)
> > > 
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):2
> > 
> > it's rails - basically
> > 
> > class Symbol  
> > def to\_proc  
> > &nbsp;&nbsp;&nbsp;sym = self  
> > &nbsp;&nbsp;&nbsp;lambda{|obj| obj.send sym}  
> > end  
> > end
> 
> --  
> Rick DeNatale
> 
> My blog on Ruby  
> [http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![Oliver\_Sauders](https://avatars.discourse-cdn.com/v4/letter/o/ecc23a/32.png) [@Oliver\_Sauders](https://rubytalk.org/u/Oliver_Sauders)\
**Post date:** [11 July 2008 02:03 UTC](https://rubytalk.org/t/map-with-method-name/47638/4 "2008-07-11T02:03:04Z")

</div>

ara.t.howard wrote:

> **···**
>
> > On Jul 10, 2008, at 3:11 PM, Oliver Saunders wrote:
> > 
> > > I see this a lot but it doesn't work for me in IRB. Is a gem  
> > > required or  
> > > something?
> > > 
> > > > > [1,2,3].map(&:to\_s)
> > > 
> > > TypeError: wrong argument type Symbol (expected Proc)  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):2
> > 
> > it's rails - basically
> > 
> > class Symbol  
> > &nbsp;&nbsp;&nbsp;def to\_proc  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sym = self  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lambda{|obj| obj.send sym}  
> > &nbsp;&nbsp;&nbsp;end  
> > end
> > 
> > a @ [http://codeforpeople.com/](http://codeforpeople.com/)
> 
> OK thanks guys. I found the actual definition:
> 
> class Symbol  
> &nbsp;&nbsp;def to\_proc  
> &nbsp;&nbsp;&nbsp;&nbsp;Proc.new { |\*args| args.shift.\_\_send\_\_(self, \*args) }  
> &nbsp;&nbsp;end  
> end
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
