GithubHelp home page GithubHelp logo

ruby-calculator-challenge's Introduction

General Assembly Logo

Ruby Calculator Challenge

Prerequisites

Requirements

  • Create new instances of a Calculator class with an initialized value
  • Access calculator methods from this class within pry when running ruby bin/calc.rb
  • Return Floats vs Fixnums for true values

Instructions

In bin/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

After running ruby bin/calc.rb, and in your pry console, you should be able to create a new instance of your Calculator class and chain a calculation method to it to receive the correct answer.

Be aware of whether your methods are returning Float or Fixnum results.

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) #=> 5

Source code distributed under the MIT license. Text and other assets copyright General Assembly, Inc., all rights reserved.

ruby-calculator-challenge's People

Contributors

tibbon avatar laurenfazah avatar jrhorn424 avatar tdyer avatar fishermanswharff avatar

Watchers

James Cloos avatar Misha Herscu 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.