Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.