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?
Methods included from Value
#inspect, #pretty_print, #to_s
Methods included from Matching
#any, #match, #match?, #on
Constructor Details
#initialize(*fields) ⇒ Abstract
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
56
57
58
|
# File 'lib/algebrick/product_constructors/abstract.rb', line 56
def self.name
@type.to_s
end
|
60
61
62
|
# File 'lib/algebrick/product_constructors/abstract.rb', line 60
def self.to_s
name
end
|
48
49
50
|
# File 'lib/algebrick/product_constructors/abstract.rb', line 48
def self.type
@type || raise
end
|
.type=(type) ⇒ Object
64
65
66
67
68
69
|
# File 'lib/algebrick/product_constructors/abstract.rb', line 64
def self.type=(type)
Type! type, ProductVariant
raise if @type
@type = type
include type
end
|
Instance Method Details
#==(other) ⇒ Object
Also known as:
eql?
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
|
44
45
46
|
# File 'lib/algebrick/product_constructors/abstract.rb', line 44
def hash
[self.class, @fields].hash
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
|
52
53
54
|
# File 'lib/algebrick/product_constructors/abstract.rb', line 52
def type
self.class.type
end
|
#update(*fields) ⇒ Object
71
72
73
|
# File 'lib/algebrick/product_constructors/abstract.rb', line 71
def update(*fields)
raise NotImplementedError
end
|