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

def full_name_with_affiliation_and_position
  a_ap = " (#{a_ap})" unless (a_ap = [affiliation, academic_position].compact.join ', ').empty?
  "#{full_name}#{a_ap}"


end



On Friday, 8 February 2013 г. at 17:41, alexeymuranov (Alexey Muranov) wrote:

>  
> Issue #6721 has been updated by alexeymuranov (Alexey Muranov).
>  
>  
> =begin
> Here is a "real life" use case. It again has to do with formatting strings.
>  
> I want to have a list of conference participants in the form:
> Full 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:
>  
> class Participant
> def full_name_with_affiliation_and_position
> full_name +
> lambda { |a_ap| a_ap.empty? ? '' : " (#{ a_ap })" }[[affiliation, academic_position].compact.join(', ')]
> end
> end
>  
> (I will appreciate any more elegant solution.)
>  
> With (({#yield_self})) (or any other name for it), i would haveritten:
>  
> class Participant
> def full_name_with_affiliation_and_position
> full_name +
> [affiliation, academic_position].compact.join(', ')].yield_self { |a_ap| a_ap.empty? ? '' : " (#{ a_ap })" }nd
> end
>  
> This would be a bit more readable for me.
> =end
>  
> ----------------------------------------
> Feature #6721: Object#yield_self
> https://bugs.ruby-lang.org/issues/6721#change-36056
>  
> Author: alexeymuranov (Alexey Muranov)
> Status: Open
> Priority: Normal
> Assignee:  
> Category: core
> Target version: next minor
>  
>  
> =begin
> I think the following method is missing from Ruby:
>  
> class Object
> def yield_self(*args)
> yield(self, *args)
> end
> end
>  
> I do not know a good use case, but it looks very natural to me. It can be used in method chains.
>  
> What do you think? Is there an alternative?
> =end
>  
>  
>  
> --  
> http://bugs.ruby-lang.org/
>  
>  



--511555f2_5a9cc3e5_fad9
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline


                <div style="font-family: Helvetica; font-size: 13px; ">Why you can't simply do the following?<div><br></div><div>def&nbsp;full_name_with_affiliation_and_position<br><div>&nbsp;&nbsp;a_ap&nbsp;= " (#{a_ap})" unless (a_ap&nbsp;= [affiliation,&nbsp;academic_position].compact.join ', ').empty?<div>&nbsp; "#{full_name}#{a_ap}"</div></div></div><div>end</div></div>
                <div></div>
                 
                <p style="color: #A0A0A8;">On Friday, 8 February 2013&nbsp;г. at 17:41, alexeymuranov (Alexey Muranov) wrote:</p>blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-left:0px;padding-left:10px;">
                    <span><div><div><div><br></div><div>Issue #6721 haseen updated by alexeymuranov (Alexey Muranov).</div><div><br></div><div><br></div><div>=begin</div><div>Here is a "real life" use case.  It again has to do with formatting strings.</div><div><br></div><div>I want to have a list of conference participants in the form:</div><div> Full Name (Affiliation, academic position)</div><div>but without empty parentheses or trailing comma if the person has not</div><div>profided the affiliation or the position.  So i did like this:</div><div><br></div><div> lass Participant</div><div>    def full_name_with_affiliation_and_position</div><div>      full_name +</div><div>        lambda { |a_ap| a_ap.empty? ? '' : " (#{ a_ap })" }[[affiliation, academic_position].compact.join(', ')]</div><div>    end</div><div>  end</div><div><br></div><div>(I will appreciate any more elegant solution.)</div><div><br></div><div>With (({#yield_self}))or any other name for it), i would have written:</div><div><br></div><div>  class Participant</div><div>    def full_name_with_affiliation_and_position</div><div>      full_name +</div><div>        [affiliation, academic_position].compact.join(', ')].yield_self { |a_ap| a_ap.empty? ? '' : " (#{ a_ap })" }</div><div>    end</div><div>  end</div><div><br></div><div>This would be a bit more readable for me.</div><div>=end</div><div><br></div><div>----------------------------------------</div><div>Feature #6721: Object#yield_self</div><div>https://bugs.ruby-lang.org/issues/6721#change-36056</div><div><br></div><div>Author: alexeymuranov (Alexey Muranov)</div><div>Status: Open</div><div>Priority: Normal</div><div>Assignee: </div><div>Category: core</div><div>Target version: next minor</div><div><br></div><div><br></div><div>=begin</div><div>I think the following method is missing from Ruby:</div><div><br></div><div> class Object</div><div>   def yield_self(*args)</div><div>     yield(self, *args)</div><div>   end</div><div> end</div><div><br></div><div>I do not know a good use case, but it looks very natural to me.  It can be used in method chains.</div><div><br></div><div>What do you think?  Is there an alternative?</div><div>=end</div><div><br></div><div><br></div><div><br></div><div>-- </div><div>http://bugs.ruby-lang.org/</div></div></div></span>
                 
                 
                 
                 
                </blockquote>
                 
                <div>
                    <br>
                </div>
            
--511555f2_5a9cc3e5_fad9--