Skip to content

Instantly share code, notes, and snippets.

@bernEsp
Created February 6, 2015 17:52
Show Gist options
  • Save bernEsp/6919f283761c92cc19c4 to your computer and use it in GitHub Desktop.
Save bernEsp/6919f283761c92cc19c4 to your computer and use it in GitHub Desktop.
object collection wrap with a presenter that can be render by render method rails 3.0
class FooCollectionPresenter < SimpleDelegator
include Enumerable
def iterate_with_index
self.each_with_index do |foo, index|
yield(FooPresenter.new(foo), index)
end
end
def iterate
self.map do |foo|
yield(FooPresenter.new(foo))
end
end
def to_ary
self.map do |foo|
FooPresenter.new(foo)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment