Created
September 29, 2015 19:51
-
-
Save sighmin/34837102b3421dbc286f to your computer and use it in GitHub Desktop.
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
def decorate(object, decorater = nil) | |
if object.is_a? Array | |
return [] if object.empty? | |
decorater_class = decorater || (object[0].class.name.split("::").last + "View").constantize | |
object.map { |o| decorater_class.new(o) } | |
else | |
decorater_class = decorater || (object.class.name + "View").constantize | |
decorater_class.new(object) | |
end | |
end | |
user = decorate(current_user) | |
users = decorate(User.popular(10)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment