Created
January 27, 2020 14:38
-
-
Save zaagan/46865271edae8b3fd3ce93ae81ee4eda to your computer and use it in GitHub Desktop.
Ruby Basicsl - Modules
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
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