Create a gist now

Instantly share code, notes, and snippets.

Embed
Decorate an Enumerable collection
class FancyDecorator < SimpleDelegator
def full_name
"#{first_name} #{last_name}"
end
def last_name_first
"#{last_name}, #{first_name}"
end
def self.decorate_collection(collection)
DecoratableCollectionProxy.new collection
end
class DecoratableCollectionProxy < SimpleDelegator
def each
__getobj__.each do |object|
yield FancyDecorator.new object
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment