From: wycats@... Date: 2015-10-26T12:25:26+00:00 Subject: [ruby-core:71186] [Ruby trunk - Feature #11537] Introduce "Safe navigation operator" Issue #11537 has been updated by Yehuda Katz. Yukihiro Matsumoto wrote: > I like the idea. My remaining concern is ".?" is too similar to "?." which is chosen by other languages. > We cannot use "?." since it conflicts with a method call with a "*?" predicate method. > > Matz. I agree with this concern. I also agree with the idea of trying to make it more like a traditional infix operator by encouraging spaces. What about: ~~~ u && .profile && .thumbnails && .large ~~~ As shorthand for: ~~~ u && u.profile && u.profile.thumbnails && u.profile.thumbnails.large ~~~ It reads nicely to me and its meaning is clear. It also doesn't conflict with Ruby's method predicates (`?` suffix). Matz, what do you think? ---------------------------------------- Feature #11537: Introduce "Safe navigation operator" https://bugs.ruby-lang.org/issues/11537#change-54565 * 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/