- Fork and clone this repository.
- Change into the new directory.
- Install dependencies.
- Create and checkout a new branch to work on.
- Fulfill the listed requirements.
Starter code is available in lib/calc.rb
. A pull request is not
required, but it is necessary if you want a code review.
You may wish to refer to FAQs related to forking, cloning.
In lib/calc.rb
, create a Calculator
class with an initialize
method that takes a starting number. You should then create calculation methods
for each of the following operations that take a second number to perform a
calculation on:
- Addition
- Subtraction
- Multiplication
- Division
In addition, there should be an equals
method and a clear
method.
equals
should return the current calculated value. For example:
calculator = Calculator.new(5)
calculator.equals # 5
calculator.add(3)
calculator.equals # 8
clear
should reset the current calculated value to 0. For example:
calculator = Calculator.new(5)
calculator.equals # 5
calculator.clear
calculator.equals # 0
You should be able to create a new instance of your Calculator
class and chain
a calculator method to it to receive the correct answer by running pry
and
executing require_relative 'lib/calc'
.
Be aware of whether your methods are returning Float or Fixnum results.
- Create new instances of a
Calculator
class with an initialized value - Access calculator methods from this class within
pry
by executingrequire_relative 'lib/calc'
- Return
Floats
vsFixnums
for true values
Research Ruby's self
,
specifically in regards to method chaining,
and refactor your Calculator
class to allow for multiple chained calculations.
For example:
Calculator.new(5).add(3).multiply(2).subtract(1).divide(3).equals #=> 5
- All content is licensed under a CCBYNCSA 4.0 license.
- All software code is licensed under GNU GPLv3. For commercial use or alternative licensing, please contact [email protected].