Skip to content

Instantly share code, notes, and snippets.

@thiagofm
Last active October 18, 2022 19:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thiagofm/3743af90e174a4317888d494277902ca to your computer and use it in GitHub Desktop.
Save thiagofm/3743af90e174a4317888d494277902ca to your computer and use it in GitHub Desktop.
Include vs Extend
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