Module: Algebrick::FieldMethodReaders

Included in:
ParametrizedType, ProductVariant
Defined in:
lib/algebrick/field_method_readers.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) add_all_field_method_readers



38
39
40
41
# File 'lib/algebrick/field_method_readers.rb', line 38

def add_all_field_method_readers
  add_field_method_readers *field_names
  self
end

- (Object) add_field_method_reader(field)

Raises:

  • (TypeError)


25
26
27
28
29
30
31
# File 'lib/algebrick/field_method_readers.rb', line 25

def add_field_method_reader(field)
  raise TypeError, 'no field names' unless field_names?
  raise ArgumentError, "no field name #{field}" unless field_names.include? field
  raise ArgumentError, "method #{field} already defined" if instance_methods.include? field
  define_method(field) { self[field] }
  self
end

- (Object) add_field_method_readers(*fields)



33
34
35
36
# File 'lib/algebrick/field_method_readers.rb', line 33

def add_field_method_readers(*fields)
  fields.each { |f| add_field_method_reader f }
  self
end

- (Object) field_names



17
18
19
# File 'lib/algebrick/field_method_readers.rb', line 17

def field_names
  @field_names or raise TypeError, "field names not defined on #{self}"
end

- (Boolean) field_names?

Returns:



21
22
23
# File 'lib/algebrick/field_method_readers.rb', line 21

def field_names?
  !!@field_names
end