Project

General

Profile

Actions

Feature #6841

open

Shorthand for Assigning Return Value of Method to Self

Added by wardrop (Tom Wardrop) over 11 years ago. Updated over 3 years ago.

Status:
Assigned
Target version:
-
[ruby-core:47036]

Description

=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


Related issues 1 (0 open1 closed)

Has duplicate Ruby master - Feature #19027: .= syntaxRejectedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0