Class: Domain::HeadingBased

Inherits:
Module
  • Object
show all
Defined in:
lib/alf/ext/domain/heading_based.rb

Defined Under Namespace

Classes: AlgebraMethods, DomainMethods

Constant Summary collapse

EMPTY_SET =
Set.new.freeze

Instance Method Summary collapse

Constructor Details

#initialize(master_class) ⇒ HeadingBased


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/alf/ext/domain/heading_based.rb', line 6

def initialize(master_class)
  define_method(:new){|*args|
    raise "#{master_class}.new may not be called directly" if master_class==self
    super(*args)
  }
  define_method(:type){|generating_type={},&bl|
    clazz = Class.new(master_class)
    if bl
      generating_type = generating_type.to_heading.to_hash unless generating_type.is_a?(Hash)
      generating_type = generating_type.merge(bl.call(clazz))
    end
    meths = [
      DomainMethods.new(master_class, generating_type),
      AlgebraMethods.new(master_class, generating_type),
      Domain::Comparisons,
    ]
    clazz.extend(*meths).heading_based_factored
  }
  alias_method :[], :type
  define_method(:heading_based_factored) do
    self
  end
end