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