--0016e65bcd34a2499a047724c597
Content-Type: text/plain; charset=ISO-8859-1
In fact, I knew about about the 1.8 implementations. I just forgot about it.
Thank to have cleared my ideas.
The current implementation looks like (of course it must be in C):
class Symbol
def to_proc
@to_proc || roc.new { |*args| args.shift.send(self, *args) }
end
end
2009/10/30 Rick DeNatale <rick.denatale / gmail.com>
> On Thu, Oct 29, 2009 at 2:14 PM, Benoit Daloze <eregontp / gmail.com> wrote:
> > Hi rubyists,
> >
> > I was just wondering why,
> >
> > (1..4).inject(&:+) # 10
> >
> > works ? (in Ruby 1.9.2)
> >
> > I understand easily these:
> >
> > (1..4).inject { |s, e| s + e } # 10
> > (1..4).inject(:+) # 10
> >
> > I suppose it's calling :+.to_proc # #<Proc:0x2f52d8>
> >
> > irb> def a(&b); b; end
> > irb> a(&:+)
> >