Module: Algebrick::FieldMethodReaders
- Included in:
- ParametrizedType, ProductVariant
- Defined in:
- lib/algebrick/field_method_readers.rb
Instance Method Summary (collapse)
-
- (Object) add_all_field_method_readers
-
- (Object) add_field_method_reader(field)
-
- (Object) add_field_method_readers(*fields)
-
- (Object) field_names
-
- (Boolean) field_names?
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)
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?
21 22 23 |
# File 'lib/algebrick/field_method_readers.rb', line 21 def field_names? !!@field_names end |