Skip to content

Instantly share code, notes, and snippets.

@thiagoa
Last active December 20, 2016 02:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thiagoa/f115449d7a5cf61ef1073dba34d6d350 to your computer and use it in GitHub Desktop.
Save thiagoa/f115449d7a5cf61ef1073dba34d6d350 to your computer and use it in GitHub Desktop.
module Imageable
def self.build(methods)
mod = Module.new do
methods.each do |method|
define_method method do
images.find { |image| image.kind == 'main_image' }
end
end
end
mod.define_singleton_method :included do |model_class|
model_class.has_many :images
end
mod
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment