Skip to content

Commit 13ddb51

Browse files
committed
Fix typo in Trace#respond_to_missing? (close #490)
1 parent 6158d2f commit 13ddb51

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/dry/schema/trace.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module Schema
77
# @api private
88
class Trace < ::BasicObject
99
INVALID_PREDICATES = %i[key?].freeze
10+
RESPOND_TO_MISSING_METHOD = ::Kernel.instance_method(:respond_to_missing?)
1011

1112
include ::Dry::Equalizer(:compiler, :captures)
1213

@@ -86,12 +87,13 @@ def reduced_rule
8687
end
8788

8889
def respond_to_missing?(meth, include_private = false)
89-
super || (meth.to_s.end_with?(QUESTION_MARK) && compuiler.support?(meth))
90+
RESPOND_TO_MISSING_METHOD.bind_call(self, meth, include_private) ||
91+
(meth.to_s.end_with?(QUESTION_MARK) && compiler.support?(meth))
9092
end
9193

9294
# @api private
9395
def method_missing(meth, *args, &block)
94-
if meth.to_s.end_with?(QUESTION_MARK)
96+
if !meth.equal?(:respond_to_missing?) && meth.to_s.end_with?(QUESTION_MARK)
9597
if ::Dry::Schema::Trace::INVALID_PREDICATES.include?(meth)
9698
::Kernel.raise InvalidSchemaError, "#{meth} predicate cannot be used in this context"
9799
end

spec/unit/dry/schema/trace_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,18 @@
3131
expect { trace.not_here }.to raise_error(NoMethodError, /not_here/)
3232
end
3333
end
34+
35+
describe "#respond_to?" do
36+
let(:respond_to) do
37+
Kernel.instance_method(:respond_to?)
38+
end
39+
40+
it "returns true for predicates" do
41+
expect(respond_to.bind_call(trace, :eql?)).to be(true)
42+
end
43+
44+
it "returns false for other methods" do
45+
expect(respond_to.bind_call(trace, :not_here?)).to be(false)
46+
end
47+
end
3448
end

0 commit comments

Comments
 (0)