Module: Taipo::Result

Defined in:
lib/taipo/result.rb

Overview

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

Result works by:

  1. adding the 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 Result makes the result keyword available to classes, the documentation for this method is in ClassMethods.

Since:

  • 1.5.0

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Parameters:

  • base (Class)

    the class including this module

Since:

  • 1.5.0



30
31
32
33
34
35
36
# 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