Created
February 6, 2015 17:52
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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