Skip to content

Instantly share code, notes, and snippets.

@romiras
Created November 29, 2024 23:42
Show Gist options
  • Save romiras/a9eef1be055eb7f0d627e10cbb918808 to your computer and use it in GitHub Desktop.
Save romiras/a9eef1be055eb7f0d627e10cbb918808 to your computer and use it in GitHub Desktop.
Ruby's include vs extend explained
module Mod
  def x
     puts "x"
  end
end

class C1
  extend Mod
end

class C2
  include Mod
end

C1.x - will work

C2.x - will not, but C2.new.x will

In essence

  • extend - class level
  • include - instance level
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment