Last active
December 20, 2016 02:14
-
-
Save thiagoa/0e19f4722fadac6e15fb5a098d4ad0ff to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Imageable < Module | |
def initialize(has_one: %i(main_image)) | |
has_one.each do |image_kind| | |
define_method image_kind do | |
images.find { |image| image.kind == 'main_image' } | |
end | |
end | |
end | |
def included(model_class) | |
model_class.has_many :images | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment