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) ⇒ 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

Returns:

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