Inheriting from class Module

Viewed 306

I am trying to understand the shrine gem source code that is a toolkit for file attachments. You can define an uploader on your model in rails like so:

class Picture < ApplicationRecord
  include ImageUploader::Attachment.new(:image) 
end

The class definition for Attachment can be found at this link.

This is all it is:

class Attachment < Module
  @shrine_class = ::Shrine
end

My assumption is that this allows you to instantiate the class in the include so that the methods are now available where you included it, similar to a mixin. Is Module a ruby class? How exactly does this work?

Edit:

For clarity, ImageUploader is defined in my app like so:

class ImageUploader < Shrine
  plugin :remove_attachment
end

So ImageUploader::Attachment.new(:image) is using that Attachment class defined in Shrine.

3 Answers
Related