umn-enhs/ncs_staff_portal — comment on commit 7daebd84d9129ce55ca8d6d013ece46fdac13fc6
File: config/initializers/system_configuration.rb line 52
By rsutphin:

The Rails equivalent of the `?.` operator in groovy is the `try` method:

```ruby
mdes.types.find { |t| t.name == list_name }.
try(:code_list).
try(:find, &lambda { |item| item.value == id }).
try(:label)
```

(I say "Rails" rather than "Ruby equivalent" because `try` is not provided by the language itself, but rather by ActiveSupport, Rails' collection of core library extensions.)

An alternative that doesn't use `try`:

```ruby
mdes.types.
select { |t| t.name == list_name }.
select { |t| t.code_list }.
collect { |t| t.code_list.find { |item| item.value == id } }.
compact.
collect(&:label).
first
```

Since it works with lists the whole time, there's never a chance for a `nil` dereference.