Skip to content

Commit

Permalink
Merge pull request #911 from y-yagi/improve-delegate_all-performance
Browse files Browse the repository at this point in the history
Improve performance of method call via `delegate_all`
  • Loading branch information
y-yagi authored Sep 4, 2024
2 parents a1439ff + cf2a40d commit 7093384
Showing 1 changed file with 14 additions and 4 deletions.
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)

object.respond_to?(method)
end
end

module ClassMethods
Expand Down

0 comments on commit 7093384

Please sign in to comment.