Class: Algebrick::ProductConstructors::Abstract
- Inherits:
-
Object
- Object
- Algebrick::ProductConstructors::Abstract
show all
- Extended by:
- TypeCheck
- Includes:
- Value
- Defined in:
- lib/algebrick/product_constructors/abstract.rb
Instance Attribute Summary (collapse)
Class Method Summary
(collapse)
Instance Method Summary
(collapse)
Methods included from TypeCheck
Child!, Child?, Match!, Match?, Type!, Type?, error
Methods included from Value
#inspect, #pretty_print, #to_s
Methods included from Matching
#any, #match, match_value, #on
Constructor Details
- (Abstract) initialize(*fields)
Returns a new instance of Abstract
22
23
24
25
26
27
|
# File 'lib/algebrick/product_constructors/abstract.rb', line 22
def initialize(*fields)
if fields.size == 1 && fields.first.is_a?(Hash)
fields = type.field_names.map { |k| fields.first[k] }
end
@fields = fields.zip(self.class.type.fields).map { |field, type| Type! field, type }.freeze
end
|
Instance Attribute Details
Returns the value of attribute fields
20
21
22
|
# File 'lib/algebrick/product_constructors/abstract.rb', line 20
def fields
@fields
end
|
Class Method Details
50
51
52
|
# File 'lib/algebrick/product_constructors/abstract.rb', line 50
def self.name
@type.to_s
end
|
54
55
56
|
# File 'lib/algebrick/product_constructors/abstract.rb', line 54
def self.to_s
name
end
|
42
43
44
|
# File 'lib/algebrick/product_constructors/abstract.rb', line 42
def self.type
@type || raise
end
|
+ (Object) type=(type)
58
59
60
61
62
63
|
# File 'lib/algebrick/product_constructors/abstract.rb', line 58
def self.type=(type)
Type! type, ProductVariant
raise if @type
@type = type
include type
end
|
Instance Method Details
- (Object) ==(other)
37
38
39
40
|
# File 'lib/algebrick/product_constructors/abstract.rb', line 37
def ==(other)
return false unless other.kind_of? self.class
@fields == other.fields
end
|
33
34
35
|
# File 'lib/algebrick/product_constructors/abstract.rb', line 33
def to_a
@fields
end
|
29
30
31
|
# File 'lib/algebrick/product_constructors/abstract.rb', line 29
def to_ary
@fields
end
|
46
47
48
|
# File 'lib/algebrick/product_constructors/abstract.rb', line 46
def type
self.class.type
end
|
- (Object) update(*fields)
65
66
67
|
# File 'lib/algebrick/product_constructors/abstract.rb', line 65
def update(*fields)
raise NotImplementedError
end
|