Created
December 24, 2018 11:40
-
-
Save zgfif/5e84d1e164a396f37f6243e820e72545 to your computer and use it in GitHub Desktop.
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
class Calculator | |
def initialize(var_x, var_y) | |
@var_x = var_x | |
@var_y = var_y | |
end | |
def divide | |
@var_x / @var_y | |
end | |
end | |
class Divider | |
def initialize(var_x, var_y) | |
@var_x = var_x | |
@var_y = var_y | |
end | |
def calculate | |
calculator.divide | |
end | |
private | |
def calculator | |
@calculator ||= Calculator.new @var_x, @var_y | |
end | |
class << self | |
def calculate(*args) | |
new(*args).calculate | |
end | |
end | |
end | |
p Divider.calculate(3.0, 4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment