Class: Wizypay::Collection
- Inherits:
-
Object
- Object
- Wizypay::Collection
- Includes:
- Enumerable
- Defined in:
- lib/wizypay/collection.rb
Instance Method Summary collapse
-
#initialize(klass, data, meta = {}) ⇒ Collection
constructor
A new instance of Collection.
- #method_missing(m, *args, &block) ⇒ Object
- #respond_to?(m) ⇒ Boolean
Constructor Details
#initialize(klass, data, meta = {}) ⇒ Collection
Returns a new instance of Collection.
4 5 6 7 |
# File 'lib/wizypay/collection.rb', line 4 def initialize(klass, data, = {}) @data = data.map {|h| klass.new(h)} @meta = || {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/wizypay/collection.rb', line 13 def method_missing(m, *args, &block) if data.respond_to?(m) data.send(m, *args, &block) elsif .has_key?(m.to_s) [m.to_s] else super end end |
Instance Method Details
#respond_to?(m) ⇒ Boolean
9 10 11 |
# File 'lib/wizypay/collection.rb', line 9 def respond_to?(m) data.respond_to?(m) || .has_key?(m.to_s) || super end |