Skip to content

Instantly share code, notes, and snippets.

@KamilLelonek
Last active October 30, 2017 00:34
Show Gist options
  • Select an option

  • Save KamilLelonek/ae7b5be2d46718688860 to your computer and use it in GitHub Desktop.

Select an option

Save KamilLelonek/ae7b5be2d46718688860 to your computer and use it in GitHub Desktop.
Ruby `extend self` example
module A
extend self
def a
puts 'a'
end
end
A.a # => 'a'
class IncludeA
include A
end
IncludeA.new.a # => 'a'
IncludeA.a # => undefined method `a' for IncludeA:Class (NoMethodError)
class ExtendA
extend A
end
ExtendA.new.a # => undefined method `a' for #<ExtendA:0x007fec4a92c500> (NoMethodError)
ExtendA.a # => 'b'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment