Sha256: e759b705ae9f5452a2d47e0481e17b6daa81438574b4b91637e5712f0116ecf2

Contents?: true

Size: 633 Bytes

Versions: 7

Compression:

Stored size: 633 Bytes

Contents

# frozen_string_literal: true

module Strict
  module Methods
    class Module < ::Module
      attr_reader :verifiable_method

      def initialize(verifiable_method)
        super()

        @verifiable_method = verifiable_method
        define_method verifiable_method.name do |*args, **kwargs, &block|
          args, kwargs = verifiable_method.verify_parameters!(*args, **kwargs)

          super(*args, **kwargs, &block).tap do |value|
            verifiable_method.verify_returns!(value)
          end
        end
      end

      def inspect
        "#<#{self.class} (#{verifiable_method.name})>"
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
strict-1.5.0 lib/strict/methods/module.rb
strict-1.4.0 lib/strict/methods/module.rb
strict-1.3.1 lib/strict/methods/module.rb
strict-1.3.0 lib/strict/methods/module.rb
strict-1.2.0 lib/strict/methods/module.rb
strict-1.1.0 lib/strict/methods/module.rb
strict-1.0.0 lib/strict/methods/module.rb