Skip to content

Instantly share code, notes, and snippets.

@zgfif
Created December 24, 2018 11:40
Show Gist options
  • Save zgfif/5e84d1e164a396f37f6243e820e72545 to your computer and use it in GitHub Desktop.
Save zgfif/5e84d1e164a396f37f6243e820e72545 to your computer and use it in GitHub Desktop.
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