Skip to content

Commit d73b40e

Browse files
thiagoaclaude
andcommitted
Inline inspector locals and tidy up comments
Replace `inspector` local variables with direct `@inspectors[object]` calls throughout InterfaceChecker. Consolidate ParamsNormalizer's class-level and inline comments into a single class-level comment, and rename `non_keywords` to `sequentials` for consistency with `SEQUENTIAL_TYPES`. Add `params` naming convention to CLAUDE.md. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent de8d989 commit d73b40e

3 files changed

Lines changed: 14 additions & 18 deletions

File tree

CLAUDE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,5 @@
4242
- Extract constants for inline literals used in conditionals.
4343
- Private methods mirror each other when they share a common role
4444
(e.g. `sort_keyword_params` / `sequentialize_params`).
45+
- Use `params` instead of `parameters` in names (e.g. method names,
46+
variable names).

lib/duck_typer/interface_checker.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@ def calculate_diff(left, right)
3232
end
3333

3434
def params_for_comparison(object, params_processor)
35-
inspector = @inspectors[object]
36-
methods = @partial_interface_methods || inspector.public_methods
35+
methods = @partial_interface_methods || @inspectors[object].public_methods
3736

3837
methods.map do |method_name|
39-
params = method_params(inspector, method_name, object)
38+
params = method_params(method_name, object)
4039
args = params_processor.call(params).map do |type, name|
4140
case type
4241
when :key then "#{name}: :opt"
@@ -54,8 +53,8 @@ def params_for_comparison(object, params_processor)
5453
end
5554
end
5655

57-
def method_params(inspector, method_name, object)
58-
inspector.parameters_for(method_name)
56+
def method_params(method_name, object)
57+
@inspectors[object].parameters_for(method_name)
5958
rescue NameError
6059
raise MethodNotFoundError, "undefined method `#{method_name}' for #{object}"
6160
end
@@ -74,8 +73,7 @@ def diff_message(left, right, diff)
7473
end
7574

7675
def join_signature(object, method_name, all_params)
77-
inspector = @inspectors[object]
78-
display_name = inspector.display_name_for(method_name)
76+
display_name = @inspectors[object].display_name_for(method_name)
7977
method_params = all_params.assoc(method_name)&.last
8078

8179
signature = if method_params

lib/duck_typer/params_normalizer.rb

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
# frozen_string_literal: true
22

33
module DuckTyper
4-
# Normalizes method parameters to enable interface comparison. For
5-
# example, two methods may use different names for positional
6-
# arguments, but if the parameter types and order match, they should
7-
# be considered equivalent. This class replaces argument names with
8-
# sequential placeholders when appropriate, focusing the comparison on
9-
# parameter structure rather than naming.
4+
# Normalizes method parameters to enable interface comparison.
5+
# Keyword argument order is irrelevant — m(a:, b:) and m(b:, a:)
6+
# are equivalent — so keywords are sorted alphabetically. Positional
7+
# argument names are also replaced with sequential placeholders,
8+
# focusing the comparison on parameter structure rather than naming.
109
class ParamsNormalizer
1110
KEYWORD_TYPES = %i[key keyreq].freeze
1211
SEQUENTIAL_TYPES = %i[req opt rest keyrest block].freeze
@@ -18,15 +17,12 @@ def call(params)
1817

1918
private
2019

21-
# Keyword argument order is irrelevant to a method's interface —
22-
# m(a:, b:) and m(b:, a:) are equivalent. Sort keyword params
23-
# alphabetically so comparison is order-independent.
2420
def sort_keyword_params(params)
25-
keywords, non_keywords = params.partition do |type, _|
21+
keywords, sequentials = params.partition do |type, _|
2622
KEYWORD_TYPES.include?(type)
2723
end
2824

29-
non_keywords + keywords.sort_by { |_, name| name }
25+
sequentials + keywords.sort_by { |_, name| name }
3026
end
3127

3228
def sequentialize_params(params)

0 commit comments

Comments
 (0)