Skip to content

Instantly share code, notes, and snippets.

@jaydorsey
Last active August 19, 2022 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaydorsey/bc80f455e3ed7dfc4edaee59aa0ea53b to your computer and use it in GitHub Desktop.
Save jaydorsey/bc80f455e3ed7dfc4edaee59aa0ea53b to your computer and use it in GitHub Desktop.
Ruby modules, classes, and instance methods
# An example of class/instance methods w/ modules
module Foo
def self.included(base)
base.extend(ClassMethods)
end
def foo
puts 'Bar.new.foo prints this'
end
def self.foo
puts 'Foo.foo prints this'
end
module ClassMethods
def foo
puts 'Bar.foo prints this'
end
end
end
class Bar
include Foo
end
Bar.new.foo
Bar.foo
Foo.foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment