Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/duck_punches/array/each_with_presenter.rb

Instance Method Summary collapse

Instance Method Details

#each_with_presenter(presenter_class, object_name, presenter_options = {}, &block) ⇒ Object

Wrap each element in the Array with a presenter specified by @presenter_class@ and assigned as the model for @object_name@. @presenter_options@ are set once on the initial presenter instance.



6
7
8
9
10
11
12
# File 'lib/duck_punches/array/each_with_presenter.rb', line 6

def each_with_presenter(presenter_class, object_name, presenter_options={}, &block)
  presenter = presenter_class.new(presenter_options)
  each do |object|
    presenter.send("#{object_name}=", object)
    yield presenter
  end
end