Class: Horza::Entities::Collection
- Inherits:
-
Object
- Object
- Horza::Entities::Collection
- Defined in:
- lib/horza/entities/collection.rb
Instance Method Summary collapse
- #[](index) ⇒ Object
-
#initialize(collection) ⇒ Collection
constructor
A new instance of Collection.
Constructor Details
#initialize(collection) ⇒ Collection
Returns a new instance of Collection.
4 5 6 |
# File 'lib/horza/entities/collection.rb', line 4 def initialize(collection) @collection = collection end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, &block) ⇒ Object (private)
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/horza/entities/collection.rb', line 14 def method_missing(method, &block) if [:length, :size, :empty?, :present?].include? method @collection.send(method) elsif [:first, :last, :pop].include? method result = @collection.send(method) singular_entity(result) unless result.nil? elsif [:each, :map, :collect] enum_method(method, &block) end end |
Instance Method Details
#[](index) ⇒ Object
8 9 10 |
# File 'lib/horza/entities/collection.rb', line 8 def [](index) singular_entity(@collection[index]) end |