From: Rodrigo Rosenfeld Rosas Date: 2011-01-20T09:27:44+09:00 Subject: [ruby-core:34632] Ruby operator equivalent to Groovy's "?." This is a multi-part message in MIME format. --------------070800070404080503060807 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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. --------------070800070404080503060807 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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.
--------------070800070404080503060807--