Class: RomFactory::Struct
- Inherits:
-
Object
- Object
- RomFactory::Struct
- Defined in:
- lib/rom_factory/struct.rb
Instance Attribute Summary collapse
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
- #define_methods ⇒ Object
-
#initialize(values) ⇒ Struct
constructor
A new instance of Struct.
- #set_values ⇒ Object
- #to_h ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(values) ⇒ Struct
Returns a new instance of Struct.
3 4 5 6 7 |
# File 'lib/rom_factory/struct.rb', line 3 def initialize(values) @values = values define_methods set_values end |
Instance Attribute Details
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
9 10 11 |
# File 'lib/rom_factory/struct.rb', line 9 def schema @schema end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
9 10 11 |
# File 'lib/rom_factory/struct.rb', line 9 def values @values end |
Instance Method Details
#define_methods ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rom_factory/struct.rb', line 11 def define_methods values.each {|k,v| define_singleton_method k, Proc.new { instance_variable_get("@#{k}") } define_singleton_method "#{k}=", Proc.new {|v| instance_variable_set("@#{k}", v) } } end |
#set_values ⇒ Object
23 24 25 26 27 |
# File 'lib/rom_factory/struct.rb', line 23 def set_values values.each do |k, v| send("#{k}=", v) end end |
#to_h ⇒ Object
33 34 35 |
# File 'lib/rom_factory/struct.rb', line 33 def to_h values end |
#to_hash ⇒ Object
29 30 31 |
# File 'lib/rom_factory/struct.rb', line 29 def to_hash to_h end |