class Algebrick::ProductConstructors::Named
Public Class Methods
type=(type)
click to toggle source
Calls superclass method
Algebrick::ProductConstructors::Abstract.type=
# File lib/algebrick/product_constructors/named.rb, line 48 def self.type=(type) super(type) raise unless type.field_names? end
Public Instance Methods
pretty_print(q)
click to toggle source
# File lib/algebrick/product_constructors/named.rb, line 23 def pretty_print(q) q.group(1, "#{self.class.type.name}[", ']') do type.field_names.each_with_index do |name, i| if i == 0 q.breakable '' else q.text ',' q.breakable ' ' end q.text name.to_s q.text ':' q.group(1) do q.breakable ' ' q.pp self[name] end end end end
to_hash()
click to toggle source
# File lib/algebrick/product_constructors/named.rb, line 42 def to_hash type.field_names.inject({}) { |h, name| h.update name => self[name] } end
Also aliased as: to_h
to_s()
click to toggle source
# File lib/algebrick/product_constructors/named.rb, line 18 def to_s "#{self.class.type.name}[" + type.field_names.map { |name| "#{name}: #{self[name].to_s}" }.join(', ') +']' end
update(fields)
click to toggle source
# File lib/algebrick/product_constructors/named.rb, line 53 def update(fields) type[to_hash.merge fields] end