Skip to content

Instantly share code, notes, and snippets.

@wm
Created August 27, 2013 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wm/6359415 to your computer and use it in GitHub Desktop.
Save wm/6359415 to your computer and use it in GitHub Desktop.
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