Last active
October 18, 2022 19:20
-
-
Save thiagofm/3743af90e174a4317888d494277902ca to your computer and use it in GitHub Desktop.
Include vs Extend
This file contains hidden or 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
module FlippedTable | |
def table | |
"┻━┻" | |
end | |
end | |
class AngryTableFlipper | |
# Including FlippedTable's methods... | |
# as instance methods | |
include FlippedTable | |
def table_flip | |
# Call table method | |
"(ノಠ益ಠ)ノ彡" + table | |
end | |
end | |
# => "(ノಠ益ಠ)ノ彡┻━┻" | |
AngryTableFlipper.new.table_flip | |
class ClassyTableFlipper | |
# Extending FlippedTable's methods... | |
# as class methods | |
extend FlippedTable | |
def table_flip | |
# Call table class method from the class itself | |
"(╯°□°)╯" + self.class.table | |
end | |
end | |
ClassyTableFlipper.new.table_flip | |
# => "(╯°□°)╯┻━┻" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment