From: "kstephens (Kurt Stephens)" Date: 2012-08-09T09:31:43+09:00 Subject: [ruby-core:47085] [ruby-trunk - Feature #6841] Shorthand for Assigning Return Value of Method to Self Issue #6841 has been updated by kstephens (Kurt Stephens). If we want lexical multiplicity to equal evaluation multiplicity... Should: obj.foo.bar[baz.daz] .= to_i behave as?: begin temp1 = obj.foo.bar temp2 = baz.daz temp1[temp2] = temp1[temp2].to_i end ... Since the following evaluates "obj.bar.baz" and "baz.daz" only once: class Obj def foo puts "#{self}#foo" @foo ||= Foo.new end end class Foo def bar puts "#{self}#bar" @bar ||= { } end end class Baz def daz puts "#{self}#daz" :x end end obj = Obj.new baz = Baz.new obj.foo.bar[baz.daz] = 1 ... Similarly for below: obj.foo.bar[baz.daz] ||= 1 ---------------------------------------- Feature #6841: Shorthand for Assigning Return Value of Method to Self https://bugs.ruby-lang.org/issues/6841#change-28739 Author: wardrop (Tom Wardrop) Status: Open Priority: Normal Assignee: Category: core Target version: 2.0.0 =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/