Class: NucleusCore::SimpleObject
- Inherits:
-
Object
- Object
- NucleusCore::SimpleObject
- Defined in:
- lib/nucleus_core/simple_object.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#__attributes__ ⇒ Object
readonly
Returns the value of attribute __attributes__.
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ SimpleObject
constructor
A new instance of SimpleObject.
- #to_h ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ SimpleObject
Returns a new instance of SimpleObject.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/nucleus_core/simple_object.rb', line 5 def initialize(attrs={}) @__attributes__ = {} attrs.each_pair do |key, value| define_singleton_method(key.to_s) do instance_variable_get("@#{key}") end define_singleton_method("#{key}=") do |val| instance_variable_set("@#{key}", val) @__attributes__[key] = val end instance_variable_set("@#{key}", value) @__attributes__[key] = value end end |
Instance Attribute Details
#__attributes__ ⇒ Object (readonly)
Returns the value of attribute __attributes__.
3 4 5 |
# File 'lib/nucleus_core/simple_object.rb', line 3 def __attributes__ @__attributes__ end |
Instance Method Details
#to_h ⇒ Object
23 24 25 |
# File 'lib/nucleus_core/simple_object.rb', line 23 def to_h __attributes__ end |