From: Nathan Broadbent Date: 2012-11-20T04:27:43+09:00 Subject: [ruby-core:49608] [ruby-trunk - Feature #7388][Open] Object#embed --e89a8fb1fe1867b1ff04cede1c7b Content-Type: text/plain; charset=ISO-8859-1 > > I'd even say that `embed` is wrong. > > I would like to know of a good example of use case. I often succumb to the > temptation of writing more complex code to avoid creating a local var, but > that doesn't always make for better code. > > The example given in the github PR was: > > [ 1, 2, 3, 4].select{|x| x.odd?}.embed{|x| {:total => x.count, :data > => x}}... > > I feel the following is clearer: > > odd_nbs = [ 1, 2, 3, 4].select{|x| x.odd?} > {:total => odd_nbs.count, :data => odd_nbs}... How about `infix`? I think this method could be a useful addition, even if it's rarely used. Also, the example usage might be clearer with a better block argument: [ 1, 2, 3, 4].select{|x| x.odd?}.infix{|odd_nbs| {:total => odd_nbs.count, :data => odd_nbs}} --e89a8fb1fe1867b1ff04cede1c7b Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
I'd even say that `embed` is wrong.

I would like to know of a good example of use case. I often succumb to the = temptation of writing more complex code to avoid creating a local var, but = that doesn't always make for better code.

The example given in the github PR was:

=A0 =A0 [ 1, 2, 3, 4].select{|x| x.odd?}.embed{|x| {:total =3D> x.count,= :data =3D> x}}...

I feel the following is clearer:

=A0 =A0 odd_nbs =3D [ 1, 2, 3, 4].select{|x| x.odd?}
=A0 =A0 {:total =3D> odd_nbs.count, :data =3D> odd_nbs}...


How about `infix`? I think this method= could be a useful addition, even if it's rarely used. Also, the exampl= e usage might be clearer with a better block argument:

=A0 =A0 =A0[ 1, 2, 3, 4].select{|x| x.= odd?}.infix{|odd_nbs| {:total =3D>=A0odd_nbs.count, :data =3D>=A0odd_= nbs}}

=A0
--e89a8fb1fe1867b1ff04cede1c7b--