Module: Functional::Record
Overview
An immutable data structure with multiple data fields. A Record is a convenient way to bundle a number of field attributes together, using accessor methods, without having to write an explicit class. The Record module generates new AbstractStruct subclasses that hold a set of fields with a reader method for each field.
A Record is very similar to a Ruby Struct and shares many of its behaviors and attributes. Unlike a # Ruby Struct, a Record is immutable: its values are set at construction and can never be changed. Divergence between the two classes derive from this core difference.
Instance Method Summary collapse
-
#new(*fields, &block) ⇒ Functional::AbstractStruct
Create a new record class with the given fields.
Instance Method Details
#new(*fields, &block) ⇒ Functional::AbstractStruct
Create a new record class with the given fields.
30 31 32 33 |
# File 'lib/functional/record.rb', line 30 def new(*fields, &block) raise ArgumentError.new('no fields provided') if fields.empty? build(fields, &block) end |