Last active
August 19, 2022 14:41
-
-
Save jaydorsey/bc80f455e3ed7dfc4edaee59aa0ea53b to your computer and use it in GitHub Desktop.
Ruby modules, classes, and instance methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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