module Taipo::Result

A simple DSL for declaring type checks to run against the return values of specified instance methods

{Taipo::Result} works by:

  1. adding the {Taipo::Result::ClassMethods#result} method to the including class;

  2. prepending a module to the ancestor chain for the including class; and

  3. defining a method on the ancestor with the same name as a particular instance method on the class and using that method to intercept method calls and check the return type.

Because of how {Taipo::Result} makes the result keyword available to classes, the documentation for this method is in {Taipo::Result::ClassMethods}.

@since 1.5.0

Public Class Methods

included(base) click to toggle source

Add the {Taipo::Result::ClassMethods#result} method to the class including this module as well as prepend a module to the ancestor chain.

@param base [Class] the class including this module

@since 1.5.0 @api private

# File lib/taipo/result.rb, line 30
def self.included(base)
  base.extend ClassMethods
  module_name = "#{base.class.name}Checker"
  checker = const_defined?(module_name) ? const_get(module_name) :
                                          const_set(module_name, Module.new)
  base.prepend checker
end