Skip to content

Instantly share code, notes, and snippets.

@chaadow
Created July 7, 2014 14:11
Show Gist options
  • Save chaadow/1a25ecfef76c27c1f0c7 to your computer and use it in GitHub Desktop.
Save chaadow/1a25ecfef76c27c1f0c7 to your computer and use it in GitHub Desktop.
class ItemDecorator
def self.build_collection(items)
items.map { |item| new(item) }
end
def initialize(item)
@item = item
end
def is_featured?
@item.ratings > 5
end
def status
if @item.sold?
"Sold on #{@item.sold_on.strftime('%A, %B %e')}"
else
"Available"
end
end
def method_missing(method_name, *args, &block)
@item.send(method_name, *args, &block)
end
def respond_to_missing?(method_name, include_private = false)
@item.respond_to?(method_name, include_private) || super
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment