In Groovy, there is a nice syntax for working with null values.
For example, I can do an if statement:
if (obj1?.obj2?.value) {
}
<
try
was the only standard way to do this before Ruby 2.3. With Ruby 2.3 you can do:
if obj1&.obj2&.value
end
Also, if you have a hash structure, you can use the _.
operator with Hashie:
require 'hashie'
myhash = Hashie::Mash.new({foo: {bar: "blah" }})
myhash.foo.bar
=> "blah"
myhash.foo?
=> true
# use "underscore dot" for multi-level testing
myhash.foo_.bar?
=> true
myhash.foo_.huh_.what?
=> false