Skip to content

Instantly share code, notes, and snippets.

@thiagoa
Last active December 20, 2016 02:06
Show Gist options
  • Save thiagoa/77f4650508ad161ff10ffaf8dae733c7 to your computer and use it in GitHub Desktop.
Save thiagoa/77f4650508ad161ff10ffaf8dae733c7 to your computer and use it in GitHub Desktop.
Imageable = Module.new
def Imageable.included(model_class)
model_class.has_many :images
end
Imageable.module_eval do
def main_image
images.find { |image| image.kind == 'main_image' }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment