Class: Algebrick::ProductConstructors::Basic

Inherits:
Abstract show all
Defined in:
lib/algebrick/product_constructors/basic.rb

Instance Attribute Summary

Attributes inherited from Abstract

#fields

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Abstract

#==, #initialize, name, #to_a, #to_ary, to_s, #type, type

Methods included from TypeCheck

#Child!, #Child?, #Match!, #Match?, #Type!, #Type?, error

Methods included from Value

#==, #inspect, #type

Methods included from Matching

#any, #match, match_value, #on

Constructor Details

This class inherits a constructor from Algebrick::ProductConstructors::Abstract

Class Method Details

+ (Object) type=(type)



37
38
39
40
# File 'lib/algebrick/product_constructors/basic.rb', line 37

def self.type=(type)
  super(type)
  raise if type.field_names?
end

Instance Method Details

- (Object) pretty_print(q)



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/algebrick/product_constructors/basic.rb', line 23

def pretty_print(q)
  q.group(1, "#{self.class.type.name}[", ']') do
    fields.each_with_index do |value, i|
      if i == 0
        q.breakable ''
      else
        q.text ','
        q.breakable ' '
      end
      q.pp value
    end
  end
end

- (Object) to_s



18
19
20
21
# File 'lib/algebrick/product_constructors/basic.rb', line 18

def to_s
  "#{self.class.type.name}[" +
      fields.map(&:to_s).join(', ') + ']'
end

- (Object) update(fields)



42
43
44
# File 'lib/algebrick/product_constructors/basic.rb', line 42

def update(fields)
  type[*fields]
end