# Symbol#to\_proc Problem

**URL:** <https://rubytalk.org/t/symbol-to-proc-problem/28240>\
**Category:** ruby-talk\
**Created:** [16 June 2006 01:40 UTC](https://rubytalk.org/t/symbol-to-proc-problem/28240 "2006-06-16T01:40:48Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elliot\_Temple](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Elliot\_Temple](https://rubytalk.org/u/Elliot_Temple)\
**Post date:** [16 June 2006 01:40 UTC](https://rubytalk.org/t/symbol-to-proc-problem/28240/1 "2006-06-16T01:40:48Z")

</div>

[http://blog.hasmanythrough.com/articles/read/8](http://blog.hasmanythrough.com/articles/read/8)

this link suggests a way to hack Symbol to allow

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

my question is how to change the hack to work correctly for other methods. details of the problem are below:

it doesn't work for reversing arrays:

curi-g5:~ curi$ ruby -v  
ruby 1.8.4 (2005-12-24) [powerpc-darwin8.5.0]

irb(main):017:0\> class Symbol  
irb(main):018:1\> def to\_proc  
irb(main):019:2\> Proc.new { |obj, \*args| obj.send(self, \*args) }  
irb(main):020:2\> end  
irb(main):021:1\> end  
=\> nil  
irb(main):022:0\> [[1,2,3], [4,5,6], [7,8,9]].map {|i| i.reverse}  
=\> [[3, 2, 1], [6, 5, 4], [9, 8, 7]]

irb(main):023:0\> [[1,2,3], [4,5,6], [7,8,9]].map &:reverse  
NoMethodError: undefined method `reverse' for 1:Fixnum  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):19:in `send'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):19:in `to\_proc'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):23  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (null):0

the problem is that \*args is capturing part of the array. here's the same thing happening without the Symbol hack involved:

irb(main):024:0\> [[1,2,3], [4,5,6], [7,8,9]].map {|i, \*args| i.reverse}  
NoMethodError: undefined method `reverse' for 1:Fixnum  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):24  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (null):0

so how should the Symbol hack be redone to work properly?

just removing \*args is no good. here is an example that needs \*args:

irb(main):027:0\> class Fixnum  
irb(main):028:1\> def foo x  
irb(main):029:2\> self+x  
irb(main):030:2\> end  
irb(main):031:1\> end  
=\> nil  
irb(main):032:0\> { 1=\>2, 3=\>4}.map &:foo  
=\> [3, 7]

so to illustrate what happens without \*args: it solves one problem while creating another:

irb(main):039:0\> class Symbol  
irb(main):040:1\> def to\_proc  
irb(main):041:2\> Proc.new { |obj| obj.send(self) }  
irb(main):042:2\> end  
irb(main):043:1\> end  
=\> nil  
irb(main):044:0\> [[1,2,3], [4,5,6], [7,8,9]].map &:reverse # works now!  
=\> [[3, 2, 1], [6, 5, 4], [9, 8, 7]]

irb(main):045:0\> { 1=\>2, 3=\>4}.map &:foo # breaks now!  
NoMethodError: undefined method `foo' for [1, 2]:Array  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):41:in `send'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):41:in `to\_proc'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):45:in `map'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):45

-- Elliot Temple

> **[Curiosity Blog](https://curi.us/blog/)**
>
> A philosophy blog

> **···**
>
> from :0

---

<div class="post-metadata">

**Author:** ![Logan\_Capaldo](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@Logan\_Capaldo](https://rubytalk.org/u/Logan_Capaldo)\
**Post date:** [16 June 2006 04:44 UTC](https://rubytalk.org/t/symbol-to-proc-problem/28240/2 "2006-06-16T04:44:36Z")

</div>

Yeah I don't believe it's possible to have this work both ways.

You could do

class Symbol  
&nbsp;&nbsp;&nbsp;def unary\_meth  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lambda { |obj| obj.send(self) }  
&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;def nary\_meth  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lambda { |obj, \*args| obj.send(self, \*args) }  
&nbsp;&nbsp;&nbsp;end  
end

[[1,2,3], [4,5,6]].map &:reverse.unary\_meth

{ 1=2, 3=\>4 }.map &:foo.nary\_meth

This is one of those cases where you can't have your cake and eat it too.

> **···**
>
> On Jun 15, 2006, at 9:40 PM, Elliot Temple wrote:
> 
> > [http://blog.hasmanythrough.com/articles/read/8](http://blog.hasmanythrough.com/articles/read/8)
> > 
> > this link suggests a way to hack Symbol to allow
> > 
> > [1, 2, 3].map(&:to\_s) # =\> ["1", "2", "3"]
> > 
> > my question is how to change the hack to work correctly for other methods. details of the problem are below:
> > 
> > it doesn't work for reversing arrays:
> > 
> > curi-g5:~ curi$ ruby -v  
> > ruby 1.8.4 (2005-12-24) [powerpc-darwin8.5.0]
> > 
> > irb(main):017:0\> class Symbol  
> > irb(main):018:1\> def to\_proc  
> > irb(main):019:2\> Proc.new { |obj, \*args| obj.send(self, \*args) }  
> > irb(main):020:2\> end  
> > irb(main):021:1\> end  
> > =\> nil  
> > irb(main):022:0\> [[1,2,3], [4,5,6], [7,8,9]].map {|i| i.reverse}  
> > =\> [[3, 2, 1], [6, 5, 4], [9, 8, 7]]
> > 
> > irb(main):023:0\> [[1,2,3], [4,5,6], [7,8,9]].map &:reverse  
> > NoMethodError: undefined method `reverse' for 1:Fixnum  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):19:in `send'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):19:in `to\_proc'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):23  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (null):0
> > 
> > the problem is that \*args is capturing part of the array. here's the same thing happening without the Symbol hack involved:
> > 
> > irb(main):024:0\> [[1,2,3], [4,5,6], [7,8,9]].map {|i, \*args| i.reverse}  
> > NoMethodError: undefined method `reverse' for 1:Fixnum  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):24  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (null):0
> > 
> > so how should the Symbol hack be redone to work properly?
> > 
> > just removing \*args is no good. here is an example that needs \*args:
> > 
> > irb(main):027:0\> class Fixnum  
> > irb(main):028:1\> def foo x  
> > irb(main):029:2\> self+x  
> > irb(main):030:2\> end  
> > irb(main):031:1\> end  
> > =\> nil  
> > irb(main):032:0\> { 1=\>2, 3=\>4}.map &:foo  
> > =\> [3, 7]
> > 
> > so to illustrate what happens without \*args: it solves one problem while creating another:
> > 
> > irb(main):039:0\> class Symbol  
> > irb(main):040:1\> def to\_proc  
> > irb(main):041:2\> Proc.new { |obj| obj.send(self) }  
> > irb(main):042:2\> end  
> > irb(main):043:1\> end  
> > =\> nil  
> > irb(main):044:0\> [[1,2,3], [4,5,6], [7,8,9]].map &:reverse # works now!  
> > =\> [[3, 2, 1], [6, 5, 4], [9, 8, 7]]
> > 
> > irb(main):045:0\> { 1=\>2, 3=\>4}.map &:foo # breaks now!  
> > NoMethodError: undefined method `foo' for [1, 2]:Array  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):41:in `send'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):41:in `to\_proc'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):45:in `map'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):45  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from :0
> > 
> > -- Elliot Temple  
> > [Curiosity Blog – Elliot Temple](http://www.curi.us/blog/)

---

<div class="post-metadata">

**Author:** ![Mauricio\_Fernandez](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@Mauricio\_Fernandez](https://rubytalk.org/u/Mauricio_Fernandez)\
**Post date:** [16 June 2006 07:26 UTC](https://rubytalk.org/t/symbol-to-proc-problem/28240/3 "2006-06-16T07:26:12Z")

</div>

FYI the "official" implementation, recently added to Ruby 1.9, works that  
way too:

$ ./ruby19 -v -e "p [[1,2,3], [4,5,6], [7,8,9]].map(&:reverse)"  
ruby 1.9.0 (2006-06-11) [i686-linux]  
-e:1: undefined method `reverse' for 1:Fixnum (NoMethodError)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from -e:1

I read that Minero Aoki was against this being added to the core[1]; maybe it  
was for the reason you exposed.

[1] [http://mput.dip.jp/mput/?date=20060611#p01](http://mput.dip.jp/mput/?date=20060611#p01)

> **···**
>
> On Fri, Jun 16, 2006 at 10:40:48AM +0900, Elliot Temple wrote:
> 
> > it doesn't work for reversing arrays:
> > 
> > curi-g5:~ curi$ ruby -v  
> > ruby 1.8.4 (2005-12-24) [powerpc-darwin8.5.0]
> > 
> > irb(main):017:0\> class Symbol  
> > irb(main):018:1\> def to\_proc  
> > irb(main):019:2\> Proc.new { |obj, \*args| obj.send(self, \*args) }  
> > irb(main):020:2\> end  
> > irb(main):021:1\> end  
> > =\> nil  
> > irb(main):022:0\> [[1,2,3], [4,5,6], [7,8,9]].map {|i| i.reverse}  
> > =\> [[3, 2, 1], [6, 5, 4], [9, 8, 7]]
> > 
> > irb(main):023:0\> [[1,2,3], [4,5,6], [7,8,9]].map &:reverse  
> > NoMethodError: undefined method `reverse' for 1:Fixnum  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):19:in `send'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):19:in `to\_proc'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):23  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (null):0
> 
> --  
> Mauricio Fernandez - [http://eigenclass.org](http://eigenclass.org) - singular Ruby

---

<div class="post-metadata">

**Author:** ![Yukihiro\_Matsumoto2](https://avatars.discourse-cdn.com/v4/letter/y/b9e5f3/32.png) [@Yukihiro\_Matsumoto2](https://rubytalk.org/u/Yukihiro_Matsumoto2)\
**Post date:** [16 June 2006 07:51 UTC](https://rubytalk.org/t/symbol-to-proc-problem/28240/4 "2006-06-16T07:51:28Z")

</div>

Hi,

> it doesn't work for reversing arrays:

> irb(main):023:0\> [[1,2,3], [4,5,6], [7,8,9]].map &:reverse  
> NoMethodError: undefined method `reverse' for 1:Fixnum

Good point. The ActiveSupport Symbol#to\_proc consider an array as a  
group of a receiver and method arguments. It was a design choice.  
You need to ask the rationale behind this design to the rails list.

As you've stated, the alternative is making everything a receiver.  
I think either choice is both good and bad. Personally I prefer the  
latter, it's more consistent. But compatibility problem would arise.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;matz.

> **···**
>
> In message "Re: Symbol#to\_proc Problem" on Fri, 16 Jun 2006 10:40:48 +0900, Elliot Temple \<curi@curi.us\> writes:

---

<div class="post-metadata">

**Author:** ![Matthew\_Harris](https://avatars.discourse-cdn.com/v4/letter/m/51bf81/32.png) [@Matthew\_Harris](https://rubytalk.org/u/Matthew_Harris)\
**Post date:** [16 June 2006 12:35 UTC](https://rubytalk.org/t/symbol-to-proc-problem/28240/5 "2006-06-16T12:35:09Z")

</div>

You could always write a String#to\_proc to accept something like [12,  
34, 56].map(&'to\_s.reverse'), but I think this is ugly. Or you may as  
well just do [12, 34, 56].map(&:to\_s).map(&:reverse) which is equally  
ugly.

But of course, the traditional [12, 34, 56].map { |x| x.to\_s.reverse }  
way exists, so why fix something that isn't broken?

> **···**
>
> On 6/16/06, Elliot Temple \<curi@curi.us\> wrote:
> 
> > [http://blog.hasmanythrough.com/articles/read/8](http://blog.hasmanythrough.com/articles/read/8)
> > 
> > this link suggests a way to hack Symbol to allow
> > 
> > [1, 2, 3].map(&:to\_s) # =\> ["1", "2", "3"]
> > 
> > my question is how to change the hack to work correctly for other  
> > methods. details of the problem are below:
> > 
> > it doesn't work for reversing arrays:
> > 
> > curi-g5:~ curi$ ruby -v  
> > ruby 1.8.4 (2005-12-24) [powerpc-darwin8.5.0]
> > 
> > irb(main):017:0\> class Symbol  
> > irb(main):018:1\> def to\_proc  
> > irb(main):019:2\> Proc.new { |obj, \*args| obj.send(self, \*args) }  
> > irb(main):020:2\> end  
> > irb(main):021:1\> end  
> > =\> nil  
> > irb(main):022:0\> [[1,2,3], [4,5,6], [7,8,9]].map {|i| i.reverse}  
> > =\> [[3, 2, 1], [6, 5, 4], [9, 8, 7]]
> > 
> > irb(main):023:0\> [[1,2,3], [4,5,6], [7,8,9]].map &:reverse  
> > NoMethodError: undefined method `reverse' for 1:Fixnum  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):19:in `send'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):19:in `to\_proc'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):23  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (null):0
> > 
> > the problem is that \*args is capturing part of the array. here's the  
> > same thing happening without the Symbol hack involved:
> > 
> > irb(main):024:0\> [[1,2,3], [4,5,6], [7,8,9]].map {|i, \*args| i.reverse}  
> > NoMethodError: undefined method `reverse' for 1:Fixnum  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):24  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (null):0
> > 
> > so how should the Symbol hack be redone to work properly?
> > 
> > just removing \*args is no good. here is an example that needs \*args:
> > 
> > irb(main):027:0\> class Fixnum  
> > irb(main):028:1\> def foo x  
> > irb(main):029:2\> self+x  
> > irb(main):030:2\> end  
> > irb(main):031:1\> end  
> > =\> nil  
> > irb(main):032:0\> { 1=\>2, 3=\>4}.map &:foo  
> > =\> [3, 7]
> > 
> > so to illustrate what happens without \*args: it solves one problem  
> > while creating another:
> > 
> > irb(main):039:0\> class Symbol  
> > irb(main):040:1\> def to\_proc  
> > irb(main):041:2\> Proc.new { |obj| obj.send(self) }  
> > irb(main):042:2\> end  
> > irb(main):043:1\> end  
> > =\> nil  
> > irb(main):044:0\> [[1,2,3], [4,5,6], [7,8,9]].map &:reverse # works now!  
> > =\> [[3, 2, 1], [6, 5, 4], [9, 8, 7]]
> > 
> > irb(main):045:0\> { 1=\>2, 3=\>4}.map &:foo # breaks now!  
> > NoMethodError: undefined method `foo' for [1, 2]:Array  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):41:in `send'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):41:in `to\_proc'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):45:in `map'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):45  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from :0
> > 
> > -- Elliot Temple  
> > [Curiosity Blog – Elliot Temple](http://www.curi.us/blog/)
> 
> --  
> Matt

---

<div class="post-metadata">

**Author:** ![Sean\_O\_Halpin](https://avatars.discourse-cdn.com/v4/letter/s/ac91a4/32.png) [@Sean\_O\_Halpin](https://rubytalk.org/u/Sean_O_Halpin)\
**Post date:** [16 June 2006 19:54 UTC](https://rubytalk.org/t/symbol-to-proc-problem/28240/6 "2006-06-16T19:54:47Z")

</div>

[snip Elliot trying to have his cake and eat it ;)]

Think about what you're trying to do here.

Applying map on its own to both input data structures gives you:

{ 1=\>2, 3=\>4}.map #=\> [[1,2], [3,4]]  
[[1,2,3], [4,5,6], [7,8,9]].map #=\> [[1,2,3], [4,5,6], [7,8,9]]

i.e. in both cases you are effectively mapping an array of arrays.

In the &:foo case, you want to apply the proc to the first element of  
each array,  
with subsequent elements as arguments. In the &:reverse case, you want to apply  
the proc to each array as a whole. How can the lambda in the to\_proc  
method know which case is which?

You might be able to devise a hack to check the arity of the methods  
involved, but even that is effectively guess work. On top of that,  
using Symbol.to\_proc in this way is very inefficient compared to using  
blocks.

IMHO this is one of those clever hacks that shouldn't make it into  
production code.

Regards,  
Sean

---

<div class="post-metadata">

**Author:** ![Elliot\_Temple](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Elliot\_Temple](https://rubytalk.org/u/Elliot_Temple)\
**Post date:** [16 June 2006 06:29 UTC](https://rubytalk.org/t/symbol-to-proc-problem/28240/7 "2006-06-16T06:29:22Z")

</div>

that is helpful, thanks

is there a reason it's important for \*args to force an array to split up, instead of just being empty?

-- Elliot Temple

> **[Curiosity Blog – Elliot Temple](https://www.curi.us/blog/)**
>
> A philosophy blog

> **···**
>
> On Jun 15, 2006, at 9:44 PM, Logan Capaldo wrote:
> 
> > Yeah I don't believe it's possible to have this work both ways.
> > 
> > You could do
> > 
> > class Symbol  
> > &nbsp;&nbsp;def unary\_meth  
> > &nbsp;&nbsp;&nbsp;&nbsp;lambda { |obj| obj.send(self) }  
> > &nbsp;&nbsp;end
> > 
> > &nbsp;&nbsp;def nary\_meth  
> > &nbsp;&nbsp;&nbsp;&nbsp;lambda { |obj, \*args| obj.send(self, \*args) }  
> > &nbsp;&nbsp;end  
> > end
> > 
> > [[1,2,3], [4,5,6]].map &:reverse.unary\_meth
> > 
> > { 1=2, 3=\>4 }.map &:foo.nary\_meth
> > 
> > This is one of those cases where you can't have your cake and eat it too.

---

<div class="post-metadata">

**Author:** ![Nobuhiro\_IMAI](https://avatars.discourse-cdn.com/v4/letter/n/9f8e36/32.png) [@Nobuhiro\_IMAI](https://rubytalk.org/u/Nobuhiro_IMAI)\
**Post date:** [16 June 2006 09:09 UTC](https://rubytalk.org/t/symbol-to-proc-problem/28240/8 "2006-06-16T09:09:27Z")

</div>

Hello,

> \>irb(main):023:0\> [[1,2,3], [4,5,6], [7,8,9]].map &:reverse  
> \>NoMethodError: undefined method `reverse' for 1:Fixnum
> 
> Good point. The ActiveSupport Symbol#to\_proc consider an array as a  
> group of a receiver and method arguments. It was a design choice.  
> You need to ask the rationale behind this design to the rails list.
> 
> As you've stated, the alternative is making everything a receiver.  
> I think either choice is both good and bad. Personally I prefer the  
> latter, it's more consistent. But compatibility problem would arise.
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;matz.

For example, I submitted [http://dev.rubyonrails.org/ticket/5295](http://dev.rubyonrails.org/ticket/5295) as follow:

class Symbol  
&nbsp;&nbsp;def to\_proc  
&nbsp;&nbsp;&nbsp;&nbsp;Proc.new{|\*args| args.shift.\_\_send\_\_(self, \*args)}  
&nbsp;&nbsp;end  
end

> > [[1,2,3], [4,5,6], [7,8,9]].map(&:reverse)

=\> [[3, 2, 1], [6, 5, 4], [9, 8, 7]]

> > (1..10).inject(&:+)

=\> 55

> > {0=\>"zero",1=\>"one",2=\>"two",3=\>"three"}.sort\_by(&:first).map(&:last)

=\> ["zero", "one", "two", "three"]

However, I wonder whether below is what we want.

> > {1=\>2,3=\>4}.map(&:reverse)

=\> [[2, 1], [4, 3]]

Thanks,

> **···**
>
> On 6/16/06, Yukihiro Matsumoto wrote:  
> --  
> Nobuhiro IMAI

---

<div class="post-metadata">

**Author:** ![James\_Edward\_Gray\_II](https://avatars.discourse-cdn.com/v4/letter/j/ea5d25/32.png) [@James\_Edward\_Gray\_II](https://rubytalk.org/u/James_Edward_Gray_II)\
**Post date:** [16 June 2006 12:57 UTC](https://rubytalk.org/t/symbol-to-proc-problem/28240/9 "2006-06-16T12:57:35Z")

</div>

I like that version better, for the official Ruby method.

James Edward Gray II

> **···**
>
> On Jun 16, 2006, at 4:09 AM, Nobuhiro IMAI wrote:
> 
> > For example, I submitted [http://dev.rubyonrails.org/ticket/5295](http://dev.rubyonrails.org/ticket/5295) as follow:
> > 
> > class Symbol  
> > def to\_proc  
> > &nbsp;&nbsp;&nbsp;Proc.new{|\*args| args.shift.\_\_send\_\_(self, \*args)}  
> > end  
> > end

---

<div class="post-metadata">

**Author:** ![Benjohn\_Barnes](https://avatars.discourse-cdn.com/v4/letter/b/df705f/32.png) [@Benjohn\_Barnes](https://rubytalk.org/u/Benjohn_Barnes)\
**Post date:** [16 June 2006 14:03 UTC](https://rubytalk.org/t/symbol-to-proc-problem/28240/10 "2006-06-16T14:03:26Z")

</div>

I'm intregued: Why wouldn't you simply use send? The Picaxe defines them  
as synonymous. I've seen arangements where all methods are stripped off  
an object (BlankSlate) except those prefixed with a \_. Is that the  
reason?

Cheers,  
&nbsp;&nbsp;Benjohn

> **···**
>
> > On Jun 16, 2006, at 4:09 AM, Nobuhiro IMAI wrote:
> > 
> > > For example, I submitted [http://dev.rubyonrails.org/ticket/5295](http://dev.rubyonrails.org/ticket/5295) as  
> > > follow:
> > > 
> > > class Symbol  
> > > def to\_proc  
> > > &nbsp;&nbsp;&nbsp;Proc.new{|\*args| args.shift.\_\_send\_\_(self, \*args)}  
> > > end  
> > > end
> > 
> > I like that version better, for the official Ruby method.

---

<div class="post-metadata">

**Author:** ![Yukihiro\_Matsumoto2](https://avatars.discourse-cdn.com/v4/letter/y/b9e5f3/32.png) [@Yukihiro\_Matsumoto2](https://rubytalk.org/u/Yukihiro_Matsumoto2)\
**Post date:** [16 June 2006 14:33 UTC](https://rubytalk.org/t/symbol-to-proc-problem/28240/11 "2006-06-16T14:33:39Z")

</div>

Hi,

> **···**
>
> In message "Re: Symbol#to\_proc Problem" on Fri, 16 Jun 2006 23:03:26 +0900, benjohn@fysh.org writes:
> 
> > I'm intregued: Why wouldn't you simply use send? The Picaxe defines them  
> > as synonymous. I've seen arangements where all methods are stripped off  
> > an object (BlankSlate) except those prefixed with a \_. Is that the  
> > reason?
> 
> The receiver may be a socket, which accidentally has send method of  
> different behavior.
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;matz.
