Issue #6721 has been updated by drbrain (Eric Hodel).


Your current names are less clear than using a local variable.  Using a local variable reveals your intentions very clearly:  

  o = object.associated_object
  attr = o.attribute if o

It's obvious that attr is only set if the associated object exists.

For your second example there's just too much going on to clearly see what the intention is.  By first separating data gathering from creating of the mailing_address Hash things become much clearer:

  address = person[:address]
  street = address[:street] if address.is_a?(Hash)

  mailing_address = {
    :name   => person[:name],
    :street => street,
  }

As in the first example, your current names don't reveal what yield_self is supposed to do in a way that's clearer than using local variables for construction of mailing_address
----------------------------------------
Feature #6721: Object#yield_self
https://bugs.ruby-lang.org/issues/6721#change-28124

Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


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