Issue #11537 has been updated by Thomas Enebo.


Eric Wong wrote:
> tom.enebo / gmail.com wrote:
>  > How about '\'?  We can pay homage to Windows file delimeter?
>  > 
>  > a\b\c
>  > 
>  > I just scanned lexer and I cannot think of a reason off the top of my head why not...what does \ mean?  who knows...what for .? mean?  I don't know that either.  This suggestion is twice as efficient though since it only uses one character.
>  
>  It's already used for continuing long lines.

well it is but that is not really an issue since it only will acknowledge '\' if right before end of line (lexer just says spaceSeen and loops back up to top of lexer for its next token).   What is really weird to me is if it isn't at the end of the line it returns as the token '\\'.  I see nowhere in the grammar where ruby acknowledges this as a valid token.  Any other literal escaping happens within lexing.  Did I just find a vestigial organ or am I missing something simple?

In any case it looks like Matz might have picked something other than .?, which was main reason I came up with \ as an idea (I feel reversing order from other languages will confuse them more than it will help -- so pick something different altogether).

-Tom

----------------------------------------
Feature #11537: Introduce "Safe navigation operator"
https://bugs.ruby-lang.org/issues/11537#change-54732

* Author: Hiroshi SHIBATA
* Status: Closed
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
I sometimes write following code with rails application:

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

or

```ruby
# 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:

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

Matz. How do you think about this?




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