Skip to content

Commit 743eec6

Browse files
committed
Don't cache Class.instance_methods
Fix: #2258 Some gems or app code may define methods on `Class` after `grape` is loaaded but before `override_all_methods!` is called. As such it's better to check `Class.method_defined?` when doing the override.
1 parent 280e5b3 commit 743eec6

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/grape/api.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module Grape
88
# should subclass this class in order to build an API.
99
class API
1010
# Class methods that we want to call on the API rather than on the API object
11-
NON_OVERRIDABLE = (Class.new.methods + %i[call call! configuration compile! inherited]).freeze
11+
NON_OVERRIDABLE = %i[call call! configuration compile! inherited].freeze
1212

1313
class Boolean
1414
def self.build(val)
@@ -51,6 +51,8 @@ def initial_setup(base_instance_parent)
5151
# Redefines all methods so that are forwarded to add_setup and be recorded
5252
def override_all_methods!
5353
(base_instance.methods - NON_OVERRIDABLE).each do |method_override|
54+
next if Class.method_defined?(method_defined)
55+
5456
define_singleton_method(method_override) do |*args, &block|
5557
add_setup(method_override, *args, &block)
5658
end

0 commit comments

Comments
 (0)