From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id 410BB17CDCA9 for ; Sat, 9 Feb 2013 05:28:43 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [133.44.2.201]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id EF50DEA620E for ; Sat, 9 Feb 2013 05:11:30 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (localhost.nagaokaut.ac.jp [127.0.0.1]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id D154897A826 for ; Sat, 9 Feb 2013 05:11:30 +0900 (JST) X-Virus-Scanned: amavisd-new at nagaokaut.ac.jp Authentication-Results: funfun.nagaokaut.ac.jp (amavisd-new); dkim=fail (2048-bit key) reason="fail (message has been altered)" header.d=gmail.com Received: from funfun.nagaokaut.ac.jp ([127.0.0.1]) by funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3MrCPtXofD3r for ; Sat, 9 Feb 2013 05:11:30 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 8471B97A82C for ; Sat, 9 Feb 2013 05:11:30 +0900 (JST) Received: from carbon.ruby-lang.org (carbon.ruby-lang.org [221.186.184.68]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id 0AD1A952408 for ; Sat, 9 Feb 2013 05:11:30 +0900 (JST) Received: from beryllium.ruby-lang.org (beryllium.ruby-lang.org [127.0.0.1]) by carbon.ruby-lang.org (Postfix) with ESMTP id 6C7643C21D392; Sat, 9 Feb 2013 05:11:28 +0900 (JST) Received: from mail-lb0-f177.google.com (mail-lb0-f177.google.com [209.85.217.177]) by carbon.ruby-lang.org (Postfix) with ESMTP id 29BC63C21F741 for ; Sat, 9 Feb 2013 05:11:26 +0900 (JST) Received: by mail-lb0-f177.google.com with SMTP id go11so3278545lbb.36 for ; Fri, 08 Feb 2013 12:11:25 -0800 (PST) Received: from [172.16.16.13] ([80.92.102.125]) by mx.google.com with ESMTPS id ns7sm17338104lab.5.2013.02.08.11.45.55 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 08 Feb 2013 11:45:55 -0800 (PST) Delivered-To: ruby-core@ruby-lang.org Date: Sat, 9 Feb 2013 05:11:28 +0900 Posted: Fri, 8 Feb 2013 23:45:54 +0400 From: Alex aka Sinm Reply-To: ruby-core@ruby-lang.org Subject: [ruby-core:52044] Re: [ruby-trunk - Feature #6721] Object#yield_self To: ruby-core@ruby-lang.org Message-Id: <9E6214F82D78444D8C39D8B5FC9D86CD@gmail.com> In-Reply-To: References: X-ML-Name: ruby-core X-Mail-Count: 52044 X-MLServer: fml [fml 4.0.3 release (20011202/4.0.3)]; post only (only members can post) X-ML-Info: If you have a question, send e-mail with the body "help" (without quotes) to the address ruby-core-ctl@ruby-lang.org; help= X-Mailer: sparrow 1.6.4 (build 1178) X-Greylist: delayed 1151 seconds by postgrey-1.27 at carbon; Sat, 09 Feb 2013 05:11:27 JST DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:date:from:to:message-id:in-reply-to:references:subject :x-mailer:mime-version:content-type; bh=oAJLSvqQbZeoOqHIpvnTyuyyOHIUXYJ+x5feGDZx78Q=; b=ZTU7lCv7wQz6R4qgRP05AmzziN10Xc8ixTzz15NdT53t7yJrtNqvGhRauyHyU9J9Z8 0rARDlfWQ6GAV8l4ZKKBJgNOQVnqcoQ/9Azsx4hY2rG2CNOywKoqzY8WEYObzHSXYCl8 T9N5MVAbgp7hnPfkaa7McCgjLpAb1DuoGUIOkDv1z38Ov1M1pxOD44Aeb1KxiUCS6JjC ARKQCQpEABdRJEt4BYrCz9MpvJrVO64jXXyhuAmXsDAwjuUUDVEqbywCKOQW8QJxsPyQ SL9rlwAScG8PU1oBc/6AOaqc83yd+1jSs77kaOFNOlAHlKcls2SnywuJ2hXcQB8PkLCM oI+w== X-Received: by 10.152.110.74 with SMTP id hy10mr2040153lab.37.1360352756702; Fri, 08 Feb 2013 11:45:56 -0800 (PST) Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="511555f2_5a9cc3e5_fad9" Precedence: bulk List-Id: ruby-core.ruby-lang.org List-Software: fml [fml 4.0.3 release (20011202/4.0.3)] List-Post: List-Owner: List-Help: List-Unsubscribe: --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

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--