Class: Burgundy::Collection
- Inherits:
-
Object
- Object
- Burgundy::Collection
- Defined in:
- lib/burgundy/collection.rb
Instance Method Summary collapse
-
#initialize(items, wrapping_class = nil, *args) ⇒ Collection
constructor
A new instance of Collection.
-
#method_missing(name, *args, &block) ⇒ Object
rubocop:disable Style/MissingRespondToMissing, Style/MethodMissingSuper.
- #respond_to?(name, include_all = false) ⇒ Boolean
- #to_ary ⇒ Object (also: #to_a)
Constructor Details
#initialize(items, wrapping_class = nil, *args) ⇒ Collection
Returns a new instance of Collection.
5 6 7 8 9 |
# File 'lib/burgundy/collection.rb', line 5 def initialize(items, wrapping_class = nil, *args) @items = items @wrapping_class = wrapping_class @args = args end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
rubocop:disable Style/MissingRespondToMissing, Style/MethodMissingSuper
11 12 13 |
# File 'lib/burgundy/collection.rb', line 11 def method_missing(name, *args, &block) # rubocop:disable Style/MissingRespondToMissing, Style/MethodMissingSuper to_ary.send(name, *args, &block) end |
Instance Method Details
#respond_to?(name, include_all = false) ⇒ Boolean
15 16 17 |
# File 'lib/burgundy/collection.rb', line 15 def respond_to?(name, include_all = false) to_ary.respond_to?(name, include_all) end |
#to_ary ⇒ Object Also known as: to_a
19 20 21 22 23 24 25 |
# File 'lib/burgundy/collection.rb', line 19 def to_ary @to_ary ||= if @wrapping_class @items.map {|item| @wrapping_class.new(item, *@args) } else @items.to_a end end |