Skip to content

Instantly share code, notes, and snippets.

@zaagan
Created January 27, 2020 14:38
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 zaagan/46865271edae8b3fd3ce93ae81ee4eda to your computer and use it in GitHub Desktop.
Save zaagan/46865271edae8b3fd3ce93ae81ee4eda to your computer and use it in GitHub Desktop.
Ruby Basicsl - Modules
module Math
def add(x, y)
x + y
end
def sub(x, y)
x - y
end
module More
def mod(x, y)
x % y
end
end
class Calculator
include Math
end
end
module Power
def get_horse_power
puts "Power of the horse !"
end
end
class MyCalculator < Math::Calculator
include Power
include Math::More
end
calc = MyCalculator.new
calc.get_horse_power
puts calc.add 1, 5
puts calc.sub 5, 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment