Module: Alf::Lang::ObjectOriented::AlgebraMethods

Included in:
Alf::Lang::ObjectOriented
Defined in:
lib/alf/lang/oo/algebra_methods.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.def_operator_method(name, clazz) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/alf/lang/oo/algebra_methods.rb', line 6

def self.def_operator_method(name, clazz)
  define_method(name) do |*args|
    # add self operands at begining of args
    args.unshift(_self_operand)

    # split operands vs. arguments
    operands, arguments = args[0...clazz.arity], args[clazz.arity..-1]

    # build the new expression
    expr = clazz.new(operands, *arguments)

    # let the abstraction have a chance to of decorating it
    _operator_output(expr)
  end
end

Instance Method Details

#!~(other) ⇒ Object


47
48
49
# File 'lib/alf/lang/oo/algebra_methods.rb', line 47

def !~(other)
  not_matching(other)
end

#&(other) ⇒ Object


39
40
41
# File 'lib/alf/lang/oo/algebra_methods.rb', line 39

def &(other)
  intersect(other)
end

#*(other) ⇒ Object


35
36
37
# File 'lib/alf/lang/oo/algebra_methods.rb', line 35

def *(other)
  join(other)
end

#+(other) ⇒ Object Also known as: |


26
27
28
# File 'lib/alf/lang/oo/algebra_methods.rb', line 26

def +(other)
  union(other)
end

#-(other) ⇒ Object


31
32
33
# File 'lib/alf/lang/oo/algebra_methods.rb', line 31

def -(other)
  minus(other)
end

#=~(other) ⇒ Object


43
44
45
# File 'lib/alf/lang/oo/algebra_methods.rb', line 43

def =~(other)
  matching(other)
end

#tuple_extractObject Also known as: tuple!

Raises:


51
52
53
54
55
56
57
58
59
60
# File 'lib/alf/lang/oo/algebra_methods.rb', line 51

def tuple_extract
  tuple = nil
  each do |t|
    raise NoSuchTupleError if tuple
    tuple = t
  end
  tuple ||= yield if block_given?
  raise NoSuchTupleError unless tuple or block_given?
  Tuple(tuple)
end