Git Product home page Git Product logo

ruby-calculator-challenge's Introduction

General Assembly Logo

Ruby Calculator Challenge

Prerequisites

Instructions

  1. Fork and clone this repository.
  2. Change into the new directory.
  3. Install dependencies.
  4. Create and checkout a new branch to work on.
  5. 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.

Requirements

  • Create new instances of a Calculator class with an initialized value
  • Access calculator methods from this class within pry by executing require_relative 'lib/calc'
  • Return Floats vs Fixnums for true values

Bonus

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

  1. All content is licensed under a CC­BY­NC­SA 4.0 license.
  2. All software code is licensed under GNU GPLv3. For commercial use or alternative licensing, please contact [email protected].

ruby-calculator-challenge's People

Contributors

bernardlee avatar tibbon avatar bengitscode avatar laurenfazah avatar jrhorn424 avatar tdyer avatar fishermanswharff avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.