Class: DuckTyper::InterfaceChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/duck_typer/interface_checker.rb,
lib/duck_typer/interface_checker/result.rb

Overview

Compares the public method signatures of two classes and reports mismatches.

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Constructor Details

#initialize(type: :instance_methods, methods: nil, strict: false, name: nil) ⇒ InterfaceChecker

Returns a new instance of InterfaceChecker.



10
11
12
13
14
15
16
# File 'lib/duck_typer/interface_checker.rb', line 10

def initialize(type: :instance_methods, methods: nil, strict: false, name: nil)
  @type = type
  @methods = methods
  @strict = strict
  @name = name
  @inspectors = Hash.new { |h, k| h[k] = MethodInspector.for(k, @type) }
end

Instance Method Details

#call(left, right) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/duck_typer/interface_checker.rb', line 18

def call(left, right)
  diff = calculate_diff(left, right)
  match = -> { diff.empty? }
  diff_message = -> { diff_message(left, right, diff) }

  Result.new(left:, right:, match:, diff_message:, name: @name, strict: @strict)
end