Singleton classes and modules?
Have you ever seen a module’s singleton class open up?
Consider what the following would do?
module Golf
def chipping
puts "chipping"
end
end
module Titleist
class << self
include Golf
def drive
puts "driving"
end
end
end
- The drive method would be available on
Titleist. - …and given we have included
Golfchipping should also be available onTitleist.
Titleist.drive
# => "driving"
Titleist.chipping
# => "chipping"
Written on November 12, 2025