Skip to content

Instantly share code, notes, and snippets.

@thiagoa
Last active December 20, 2016 02:14
Show Gist options
  • Save thiagoa/0e19f4722fadac6e15fb5a098d4ad0ff to your computer and use it in GitHub Desktop.
Save thiagoa/0e19f4722fadac6e15fb5a098d4ad0ff to your computer and use it in GitHub Desktop.
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