
Issue #19884 has been updated by p8 (Petrik de Heus). nobu (Nobuyoshi Nakada) wrote in #note-10:
Rather the extension of `defined?` operator which returns the value (instead of the expression type string) or nil.
Let's call it `defined⁉️` for now. Isn't this what you want?
```ruby defined⁉️(OptionalDependency)&.some_method ```
Yes, that would be nice. ---------------------------------------- Feature #19884: Make Safe Navigation Operator work on classes https://bugs.ruby-lang.org/issues/19884#change-104853 * Author: p8 (Petrik de Heus) * Status: Open * Priority: Normal ---------------------------------------- If a constant isn't defined it will raise a NameError: ```ruby DoesNotExist.some_method # raises: uninitialized constant DoesNotExist (NameError) ``` In libraries that have optional dependencies, we can check if the constant is defined before calling a method on it: ```ruby defined?(OptionalDependency) && OptionalDependency.some_method ``` Currently in Ruby, the Safe Navigation Operator is used to avoid NoMethodError exceptions when calling methods on objects that may be nil. It would be nice if we could use the Safe Navigation Operator to avoid NameError on undefined constants as well. ```ruby ClassThatMightNotExist&.some_method ``` -- https://bugs.ruby-lang.org/