Class: Mpesa::Object
- Inherits:
-
Object
- Object
- Mpesa::Object
- Defined in:
- lib/mpesa/object.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Object
constructor
A new instance of Object.
- #method_missing(method, *args, &block) ⇒ Object
- #respond_to_missing?(_method, _include_private = false) ⇒ Boolean
- #to_hash ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Object
Returns a new instance of Object.
9 10 11 |
# File 'lib/mpesa/object.rb', line 9 def initialize(attributes) @attributes = OpenStruct.new(attributes) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
13 14 15 16 |
# File 'lib/mpesa/object.rb', line 13 def method_missing(method, *args, &block) attribute = @attributes.send(method, *args, &block) attribute.is_a?(Hash) ? Object.new(attribute) : attribute end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
7 8 9 |
# File 'lib/mpesa/object.rb', line 7 def attributes @attributes end |
Instance Method Details
#respond_to_missing?(_method, _include_private = false) ⇒ Boolean
18 19 20 |
# File 'lib/mpesa/object.rb', line 18 def respond_to_missing?(_method, _include_private = false) true end |
#to_hash ⇒ Object
22 23 24 |
# File 'lib/mpesa/object.rb', line 22 def to_hash attributes.to_h end |