My guess is &1 is 1.to_proc() and o is the receiver object (e.g. a.map(&0) would do a.map( -> a[0])) and the sugar diabetes thingy is a.[].to_proc(). If I'm wrong please correct me @hanachin
.
There's something similar in Kotlin though I like their implementation more.
& would implicitly call #to_proc to convert the object to Proc object.
Any object that implements the to_proc method can be converted into a proc by the & operator, and therefore con be consumed by iterators. docs.ruby-lang.org/en/2.6.0/Proc.h...
But before 2.6, #to_proc that defined in Refinements are ignored at & operator.
My guess is
&1
is1.to_proc()
ando
is the receiver object (e.g.a.map(&0)
would doa.map( -> a[0])
) and the sugar diabetes thingy isa.[].to_proc()
. If I'm wrong please correct me @hanachin .There's something similar in Kotlin though I like their implementation more.
That's correct!
&
would implicitly call#to_proc
to convert the object to Proc object.But before 2.6,
#to_proc
that defined in Refinements are ignored at&
operator.In 2.6, we can use
#to_proc
for&
operator.