Created
May 26, 2021 01:44
-
-
Save serradura/9d0d276058dfaf57cdef405f9d3d9713 to your computer and use it in GitHub Desktop.
POO em Ruby - Relacionado a thread https://t.me/rubybrasil/179048
This file contains hidden or 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 Calc | |
module Outputs | |
class InMemory | |
attr_reader :history | |
def initialize | |
@history = [] | |
end | |
def puts(value) | |
@history << value | |
end | |
end | |
class Stdout | |
def puts(value) | |
Kernel.puts(value) | |
end | |
end | |
end | |
class Operations | |
def sum(a, b) | |
a + b | |
end | |
def sub(a, b) | |
a - b | |
end | |
end | |
class Program | |
def initialize(output, operations) | |
@output = output | |
@operations = operations | |
end | |
def sum(a, b) | |
@output.puts @operations.sum(a, b) | |
end | |
end | |
end | |
output = Calc::Outputs::Stdout.new | |
operations = Calc::Operations.new | |
calc = Calc::Program.new(output, operations) | |
calc.sum(1, 1) | |
# raise "expect #{output.history.last} to be equal to 2" if output.history.last != 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment