Issue #6023 has been updated by slayer (Vlad Moskovets).


I think #6561 more convenient for storage nil'able and false'able items
----------------------------------------
Feature #6023: Add "a ?= 2" support for meaning "a = a.nil? ? 2 : a"
https://bugs.ruby-lang.org/issues/6023#change-27219

Author: rosenfeld (Rodrigo Rosenfeld Rosas)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: 2.0.0


I've just proposed this idea to Groovy and I thought the same semantics would be interesting to have in Ruby too:

http://jira.codehaus.org/browse/GROOVY-5306

This is a minor, but important, difference to the "a ||= 2" syntax.

This would be a caching/memoization operator, and it would allow code like this:

a = nil
a ?= false # a is false now
a ?= true  # a is still false

This contrasts with

a = nil
a ||= false # a is false now
a ||= true  # a is true now



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