Sha256: c81deac3eb208a18582e4b3217fc9e149879916ab274e875e37f4dde39abcb63

Contents?: true

Size: 948 Bytes

Versions: 3

Compression:

Stored size: 948 Bytes

Contents

# frozen_string_literal: true

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

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

    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
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
strict-1.5.0 lib/strict/interface.rb
strict-1.4.0 lib/strict/interface.rb
strict-1.3.1 lib/strict/interface.rb