From: "byroot (Jean Boussier) via ruby-core" Date: 2026-09-07T09:34:59+00:00 Subject: [ruby-core:126584] [Ruby Feature#22297] Module#method_defined? should have an `include_private` argument Issue #22297 has been reported by byroot (Jean Boussier). ---------------------------------------- Feature #22297: Module#method_defined? should have an `include_private` argument https://bugs.ruby-lang.org/issues/22297 * Author: byroot (Jean Boussier) * Status: Open ---------------------------------------- Active Record generate methods during boot time based on the database schema. However before defining every one of these methods it first check if it already exists, regardless of visibility, as to avoid overwriting use defined code. As a result, the following pattern is in a few hot spots: ```ruby if method_defined?(name) || private_method_defined?(name) # ... end ``` On our Rails monolith, `private_method_defined?` account for 1% of boot time, that's not massive, but it could very easily be eliminated if there was a way to check for a method existence regardless of its visibility. ### Proposal Currently `Module#method_defined?` signature is: ```ruby method_defined?(symbol, inherit=true) ``` I think we could make it: ```ruby method_defined?(symbol, inherit=true, include_all=false) ``` -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/