
Issue #19884 has been updated by p8 (Petrik de Heus). sawa (Tsuyoshi Sawada) wrote in #note-6:
Then you should edit and write that in the description.
I've updated the description. Hopefully it's more clear now.
`defined?` also handles undefined classes.
Can you show an example of that?
```ruby defined?(UndefinedConstant) # returns nil instead of raising an error ``` ---------------------------------------- Feature #19884: Make Safe Navigation Operator work on classes https://bugs.ruby-lang.org/issues/19884#change-104844 * 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/