From: "Martin J. Dürst" Date: 2011-01-20T13:00:02+09:00 Subject: [ruby-core:34639] Re: Ruby operator equivalent to Groovy's "?." I have definitely had cases where such a feature would have been very handy. I don't think it's worth a special syntax, but having a dedicated method in Ruby core, even if the name is longer than two letters, would be very helpful. Regards, Martin. On 2011/01/20 9:27, Rodrigo Rosenfeld Rosas wrote: > One of the few things I like in Groovy that Ruby doesn't support is the > '?.' operator. For instance: > > obj?.somePropertyName?.anotherGreatPropertyName?.anotherOne > > This is the same as: > > (obj == null ? null : (obj.somePropertyName == null ? null : > (obt.somePropertyName.anotherGreatPropertyName == null ? null : > obt.somePropertyName.anotherGreatPropertyName.anotherOne))) > > Unfortunately, this name cannot be used by Ruby since it accepts '?' as > part of a method name. I've seen some framework that declares a '_?' > method for doing this like 'obj._?.some_method._?.another_method'. > > I'm not sure what syntax would fit better for Ruby. I don't even know if > this is something the Ruby community is interested in as well, so I'd > like to hear your opinions on this feature. > > Regards, Rodrigo. > -- #-# Martin J. D�rst, Professor, Aoyama Gakuin University #-# http://www.sw.it.aoyama.ac.jp mailto:duerst@it.aoyama.ac.jp