Skip to content

Instantly share code, notes, and snippets.

@havenwood
Last active June 30, 2025 17:27
Show Gist options
  • Save havenwood/d97fa99fa19e0a3ea669c6cc304762e4 to your computer and use it in GitHub Desktop.
Save havenwood/d97fa99fa19e0a3ea669c6cc304762e4 to your computer and use it in GitHub Desktop.
Mixin example for #ruby IRC
module Document
def self.included(base)
base.class_eval do
def self.name = "#{super}ument"
end
end
module_function
def print = :printed
end
class Book
include Document
def publish = true && print
end
Book.new.publish
#=> :printed
Book.new.print
#!> private method 'print' called for an instance of Bookument (NoMethodError)
@havenwood
Copy link
Author

Compare with

module ClassMethods
  def name = "#{super}ument"
end

def self.included(base) = base.extend(ClassMethods)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment