From: Alex aka Sinm Date: 2013-02-09T05:11:28+09:00 Subject: [ruby-core:52044] Re: [ruby-trunk - Feature #6721] Object#yield_self --511555f2_5a9cc3e5_fad9 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Why you can't simply do the following=3F def full=5Fname=5Fwith=5Faffiliation=5Fand=5Fposition a=5Fap =3D =22 (=23=7Ba=5Fap=7D)=22 unless (a=5Fap =3D =5Baffiliation, = academic=5Fposition=5D.compact.join ', ').empty=3F =22=23=7Bfull=5Fname=7D=23=7Ba=5Fap=7D=22 end On =46riday, 8 =46ebruary 2013 =D0=B3. at 17:41, alexeymuranov (Alexey Mu= ranov) wrote: > =20 > Issue =236721 has been updated by alexeymuranov (Alexey Muranov). > =20 > =20 > =3Dbegin > Here is a =22real life=22 use case. It again has to do with formatting = strings. > =20 > I want to have a list of conference participants in the form: > =46ull Name (Affiliation, academic position) > but without empty parentheses or trailing comma if the person has not > profided the affiliation or the position. So i did like this: > =20 > class Participant > def full=5Fname=5Fwith=5Faffiliation=5Fand=5Fposition > full=5Fname + > lambda =7B =7Ca=5Fap=7C a=5Fap.empty=3F =3F '' : =22 (=23=7B a=5Fap =7D= )=22 =7D=5B=5Baffiliation, academic=5Fposition=5D.compact.join(', ')=5D > end > end > =20 > (I will appreciate any more elegant solution.) > =20 > With ((=7B=23yield=5Fself=7D)) (or any other name for it), i would have= written: > =20 > class Participant > def full=5Fname=5Fwith=5Faffiliation=5Fand=5Fposition > full=5Fname + > =5Baffiliation, academic=5Fposition=5D.compact.join(', ')=5D.yield=5Fse= lf =7B =7Ca=5Fap=7C a=5Fap.empty=3F =3F '' : =22 (=23=7B a=5Fap =7D)=22 =7D= > end > end > =20 > This would be a bit more readable for me. > =3Dend > =20 > ---------------------------------------- > =46eature =236721: Object=23yield=5Fself > https://bugs.ruby-lang.org/issues/6721=23change-36056 > =20 > Author: alexeymuranov (Alexey Muranov) > Status: Open > Priority: Normal > Assignee: =20 > Category: core > Target version: next minor > =20 > =20 > =3Dbegin > I think the following method is missing from Ruby: > =20 > class Object > def yield=5Fself(*args) > yield(self, *args) > end > end > =20 > I do not know a good use case, but it looks very natural to me. It can = be used in method chains. > =20 > What do you think=3F Is there an alternative=3F > =3Dend > =20 > =20 > =20 > -- =20 > http://bugs.ruby-lang.org/ > =20 > =20 --511555f2_5a9cc3e5_fad9 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
Why you can't simply do the following=3F

def = full=5Fname=5Fwith=5Faffiliation=5Fand=5Fposition
  a=5F= ap =3D =22 (=23=7Ba=5Fap=7D)=22 unless (a=5Fap =3D =5Baffiliati= on, academic=5Fposition=5D.compact.join ', ').empty=3F
  =22= =23=7Bfull=5Fname=7D=23=7Ba=5Fap=7D=22
end
=20

On =46riday, 8 =46ebru= ary 2013 =D0=B3. at 17:41, alexeymuranov (Alexey Muranov) wrote:

=

Issue =236721 has= been updated by alexeymuranov (Alexey Muranov).


=3Dbegin
Here is a =22real life=22 use case. I= t again has to do with formatting strings.

I wan= t to have a list of conference participants in the form:
=46ul= l Name (Affiliation, academic position)
but without empty paren= theses or trailing comma if the person has not
profided the aff= iliation or the position. So i did like this:

= class Participant
def full=5Fname=5Fwith=5Faffiliation=5Fa= nd=5Fposition
full=5Fname +
lambda =7B = =7Ca=5Fap=7C a=5Fap.empty=3F =3F '' : =22 (=23=7B a=5Fap =7D)=22 =7D=5B=5B= affiliation, academic=5Fposition=5D.compact.join(', ')=5D
e= nd
end

(I will appreciate any more e= legant solution.)

With ((=7B=23yield=5Fself=7D))= (or any other name for it), i would have written:

class Participant
def full=5Fname=5Fwith=5Faffiliation= =5Fand=5Fposition
full=5Fname +
=5Baffi= liation, academic=5Fposition=5D.compact.join(', ')=5D.yield=5Fself =7B =7C= a=5Fap=7C a=5Fap.empty=3F =3F '' : =22 (=23=7B a=5Fap =7D)=22 =7D
end
end

This would be a bit m= ore readable for me.
=3Dend

----------= ------------------------------
=46eature =236721: Object=23yiel= d=5Fself
https://bugs.ruby-lang.org/issues/6721=23change-36056=

Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee:
= Category: core
Target version: next minor

<= div>
=3Dbegin
I think the following method is mis= sing from Ruby:

class Object
def y= ield=5Fself(*args)
yield(self, *args)
end
end

I do not know a good use case, but i= t looks very natural to me. It can be used in method chains.
<= br>
What do you think=3F Is there an alternative=3F
= =3Dend



--
http://bugs.ruby-lang.org/
=20 =20 =20 =20 =20

--511555f2_5a9cc3e5_fad9--