Skip to content

Instantly share code, notes, and snippets.

@wm wm/decorator.rb
Created Aug 27, 2013

Embed
What would you like to do?
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
You can’t perform that action at this time.