Skip to content

Commit a817425

Browse files
committed
Replace methods by singleton_methods when overriding them.
1 parent 49e8e63 commit a817425

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* [#2581](https://github.com/ruby-grape/grape/pull/2581): Delegate `to_s` in Grape::API::Instance - [@ericproulx](https://github.com/ericproulx).
1111
* [#2582](https://github.com/ruby-grape/grape/pull/2582): Fix leaky slash when normalizing - [@ericproulx](https://github.com/ericproulx).
1212
* [#2583](https://github.com/ruby-grape/grape/pull/2583): Optimize api parameter documentation and memory usage - [@ericproulx](https://github.com/ericproulx).
13+
* [#2585](https://github.com/ruby-grape/grape/pull/2585): Optimize mount methods overriding - [@ericproulx](https://github.com/ericproulx).
1314
* Your contribution here.
1415

1516
#### Fixes

lib/grape/api.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Grape
55
# should subclass this class in order to build an API.
66
class API
77
# Class methods that we want to call on the API rather than on the API object
8-
NON_OVERRIDABLE = %i[call call! configuration compile! inherited recognize_path].freeze
8+
NON_OVERRIDABLE = %i[call call! configuration compile! inherited recognize_path to_s].freeze
99

1010
Helpers = Grape::DSL::Helpers::BaseHelper
1111

@@ -51,7 +51,7 @@ def initial_setup(base_instance_parent)
5151

5252
# Redefines all methods so that are forwarded to add_setup and be recorded
5353
def override_all_methods!
54-
(base_instance.methods - Class.methods - NON_OVERRIDABLE).each do |method_override|
54+
(base_instance.singleton_methods - NON_OVERRIDABLE).each do |method_override|
5555
define_singleton_method(method_override) do |*args, &block|
5656
add_setup(method: method_override, args: args, block: block)
5757
end

0 commit comments

Comments
 (0)