Project

General

Profile

Actions

Feature #11537

closed

Introduce "Safe navigation operator"

Feature #11537: Introduce "Safe navigation operator"

Added by hsbt (Hiroshi SHIBATA) about 10 years ago. Updated almost 10 years ago.

Status:
Closed
Target version:
-
[ruby-core:<unknown>]

Description

I sometimes write following code with rails application:

u = User.find(id) if u && u.profile && u.profile.thumbnails && u.profiles.thumbnails.large ... 

or

# Use ActiveSupport if u.try!(:profile).try!(:thumbnails).try!(:large) ... 

I hope to write shortly above code. Groovy has above operator named "Safe navigation operator" with "?." syntax.
Ruby can't use "?." operator.

Can we use ".?" syntax. like this:

u = User.find(id) u.?profile.?thumbnails.?large 

Matz. How do you think about this?


Related issues 4 (0 open4 closed)

Actions

Also available in: PDF Atom