Maybe it's a stupid question, but I'm very curious about it.
Ruby 2.3 introduced the "safe navigation operator", also known as lonely operator. It allows to safely navigate through methods, even if one of them returns nil
.
Many people compare this feature to Rails try
method.
The main difference I found is that try
method has the ability to call a method by parameter.
For example:
method = :my_method
myvariable.try(method)
Is there an equivalent way to do this using the &.
operator?
Aucun commentaire:
Enregistrer un commentaire