Class: DataMapper::Support::Struct
- Defined in:
- lib/data_mapper/support/struct.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(values) ⇒ Struct
constructor
A new instance of Struct.
- #method_missing(sym, *args) ⇒ Object
Constructor Details
#initialize(values) ⇒ Struct
Returns a new instance of Struct.
16 17 18 |
# File 'lib/data_mapper/support/struct.rb', line 16 def initialize(values) @values = values end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object
20 21 22 |
# File 'lib/data_mapper/support/struct.rb', line 20 def method_missing(sym, *args) @values[fields.index(sym)] end |
Class Method Details
.define(raw_fields) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/data_mapper/support/struct.rb', line 5 def self.define(raw_fields) normalized_fields = raw_fields.map { |field| Inflector.underscore(field).to_sym } Class.new(self) do define_method(:fields) do normalized_fields end end end |