Class: Burgundy::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/burgundy/collection.rb

Instance Method Summary collapse

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

Returns:

  • (Boolean)


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_aryObject 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