Class: Terrestrial::StructFactory
- Inherits:
-
Object
- Object
- Terrestrial::StructFactory
- Defined in:
- lib/terrestrial/struct_factory.rb
Instance Method Summary collapse
- #call(data) ⇒ Object
-
#initialize(struct_class) ⇒ StructFactory
constructor
A new instance of StructFactory.
Constructor Details
#initialize(struct_class) ⇒ StructFactory
Returns a new instance of StructFactory.
3 4 5 6 |
# File 'lib/terrestrial/struct_factory.rb', line 3 def initialize(struct_class) @constructor = struct_class.method(:new) @members = struct_class.members end |
Instance Method Details
#call(data) ⇒ Object
11 12 13 14 15 |
# File 'lib/terrestrial/struct_factory.rb', line 11 def call(data) constructor.call( *members.map { |m| data.fetch(m, nil) } ) end |