Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of method call via delegate_all #911

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions lib/draper/automatic_delegation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,21 @@ def respond_to_missing?(method, include_private = false)
super || delegatable?(method)
end

# @private
def delegatable?(method)
return if private_methods(false).include?(method)
# The inherit argument for `private_method_defined?` is supported since Ruby 2.6.
if RUBY_VERSION >= "2.6"
# @private
def delegatable?(method)
return if self.class.private_method_defined?(method, false)

object.respond_to?(method)
object.respond_to?(method)
end
else
# @private
def delegatable?(method)
return if private_methods(false).include?(method)
Alexander-Senko marked this conversation as resolved.
Show resolved Hide resolved

object.respond_to?(method)
end
end

module ClassMethods
Expand Down