
Issue #19884 has been updated by p8 (Petrik de Heus). There's multiple examples in the Rails code base: https://github.com/rails/rails/blob/7f7f9df8641e35a076fe26bd097f6a1b22cb4e2d... https://github.com/rails/rails/blob/7f7f9df8641e35a076fe26bd097f6a1b22cb4e2d... ```ruby def valid_type?(type) DEFAULT_TYPES.include?(type.to_s) || !defined?(ActiveRecord::Base) || ActiveRecord::Base.connection.valid_type?(type) end ``` It would be nice to rewrite this as: ```ruby def valid_type?(type) DEFAULT_TYPES.include?(type.to_s) || ActiveRecord&::Base&.connection.valid_type?(type) end ``` ---------------------------------------- Feature #19884: Make Safe Navigation Operator work on classes https://bugs.ruby-lang.org/issues/19884#change-104840 * Author: p8 (Petrik de Heus) * Status: Open * Priority: Normal ---------------------------------------- If a class might not be defined we need to add a conditional: ```ruby defined?(ActiveRecord::Base) && ActiveRecord::Base.some_method ``` It would be nice if we could use the Safe Navigation Operator instead. ```ruby ActiveRecord::Base&.some_method ``` -- https://bugs.ruby-lang.org/