Issue #6841 has been updated by Student (Nathan Zook).


http://en.wikipedia.org/wiki/Law_of_Demeter

The term that I've heard to describe obj.foo.bar.baz is "train wreck".  Encouraging such seems to me to be problematic.

I am NOT saying that the transformation/normalization is wrong, just that it is being handled a the wrong level.  Think about it.  To make this call, you have to know about obj (which I'm assuming you should).  You have to know foo about obj.  You have to know bar about obj.foo.  You have to know baz about obj.foo.bar.  And you have to know that you want baz to be an integer.  If that is not being overly intimate with your arguments, I wouldn't know what is.

If you are doing this a lot, then most likely you are normalizing a data structure.  That is, your code looks like:

obj.foo.bar.baz = obj.foo.bar.baz.to_i
obj.for.bar.boz = obj.foo.bar.boz.to_f
...

If so, the to_i part is CERTAINLY not the problem!  My first question would be "where does obj come from"?  Most likely some sort of naive deserializing process.  Many deserializers are in fact quite sophisticated, and perhaps a more informed usage would bypass ever creating the object in the undesirable form. 

I have a hard time imagining any other way that one would ever get to the point that obj.foo.bar.baz = obj.foo.bar.baz.to_i would make sense.  But perhaps I have missed something.


----------------------------------------
Feature #6841: Shorthand for Assigning Return Value of Method to Self
https://bugs.ruby-lang.org/issues/6841#change-37182

Author: wardrop (Tom Wardrop)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: Next Major


=begin
Quite often in Ruby, I find myself doing something like: (({my_var[:foo][:bar] = my_var[:foo][:bar].to_i})) or (({obj.foo.bar = obj.foo.bar.to_i})). Realising this, I thought of what would be a fairly nice shorthand syntax for this, which could be: (({my_var[:foo][:bar] .= to_i})). How this works should be pretty self-explanatory. The (({.=})) operator works exactly like any other assignment operator of this nature.

Would be nice to see this in Ruby 2.0. Wondering what others think of this?
=end


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