Module: Strict::Interface

Defined in:
lib/strict/interface.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(mod) ⇒ Object



5
6
7
8
# File 'lib/strict/interface.rb', line 5

def self.extended(mod)
  mod.extend(Strict::Method)
  mod.include(Interfaces::Instance)
end

Instance Method Details

#coercerObject



10
11
12
# File 'lib/strict/interface.rb', line 10

def coercer
  Interfaces::Coercer.new(self)
end

#expose(method_name, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/strict/interface.rb', line 14

def expose(method_name, &block)
  sig = sig(&block)
  parameter_list = [
    *sig.parameters.map { |parameter| "#{parameter.name}:" },
    "&block"
  ].join(", ")
  argument_list = [
    *sig.parameters.map { |parameter| "#{parameter.name}: #{parameter.name}" },
    "&block"
  ].join(", ")

  module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
    def #{method_name}(#{parameter_list})              # def method_name(one:, two:, three:, &block)
      implementation.#{method_name}(#{argument_list})  #   implementation.method_name(one: one, two: two, three: three, &block)
    end                                                # end
  RUBY
end