Project

General

Profile

Actions

Feature #6023

closed

Add "a ?= 2" support for meaning "a = a.nil? ? 2 : a"

Added by rosenfeld (Rodrigo Rosenfeld Rosas) almost 13 years ago. Updated about 12 years ago.

Status:
Rejected
Target version:
[ruby-core:42630]

Description

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


Related issues 1 (0 open1 closed)

Has duplicate Ruby master - Feature #6561: ?= operatorRejected06/09/2012Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0