Skip to content

Instantly share code, notes, and snippets.

@squarism
Created September 25, 2017 20:36
Show Gist options
  • Select an option

  • Save squarism/974280153d7bccba4be55b07ca052ae2 to your computer and use it in GitHub Desktop.

Select an option

Save squarism/974280153d7bccba4be55b07ca052ae2 to your computer and use it in GitHub Desktop.
Calculator with paper tape side effects
class Calculator
# add two numbers with side effects to tape
def add(number1, number2)
sum = number1 + number2
tape("#{number1} + #{number2}")
tape("=\n#{sum}")
sum
end
private
# print stuff to paper tape
def tape(message)
puts message
end
end
calculator = Calculator.new
calculator.add(1,3)
# ruby calculator.rb
# 1 + 3
# =
# 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment