Creating a simple calculator using Ruby on rails

Add, subtract, multiply, divide.

Abhishek thakur
4 min readMar 10, 2014

Ruby on rails has become the most trending web designing language among this web development world. Most of us get confused about the concept of Ruby on rails whether ruby is programming language or Ruby on rails is programming language. Actual concept is that Ruby is just a programming language and Rails is a server on which this language is compiled and executed.

Why Ruby on rails is used –

It is simple, easily readable and understandable

It can run on different platform

It is cost efficient

It is secure

It is versatile

Here , I will show you how to make simple program using Ruby on rails.

Output of this program will be a simple calculator, so let’s have a look on it.

Before you start working on ruby on rails you will have to download the Rails installer from the internet. This is done because when you write the code you will need a compiler to compile it and this rails installer will work as compiler that will execute your code and display the output of your program.

Step I — Installing Rails

1. Go to www.google.com

2. Type rails installer in search box

3. Download the rails installer

4. Now when you have completed the downloading Run this file by following steps you will see windows like below while installing Rails

Step II — Writing code

Then open your notepad from windows

Go to Start -> All programs –> Accessories –> Notepad

Type the following code into it which is of simple calculation which will perform addition, subtraction, multiplication, and division.

After you finish typing , save file as .rb extension, example calc.rb

Step III — Executing code

a) Now you will have to execute this file. For executing this file you will have to open command prompt window which will appear as icon when you will click on start button.

b) Then by clicking on command prompt with Ruby on rails you will get following screen where you will have to enter your user name ( it can be any ) for example : ruby and your email id which I have inserted in it.

c) After that your account will be created on rails server and whenever you will open command window for ruby you will get following window where you will mention path of your saved file, file name, directory name.

Eg

d) In the windows given below,

“cd..” is name of drive where you have saved you file of ruby.

“C:\Users\user\Desktop\aa\aa\New User\rubyprog” is the path of saved file.

“Ruby” is name of folder where you have saved your file and

“calc.rb” is name of file where you have written the code for calculation.

When this file is executed you will get following output of addition, subtraction, multiplication and division of two numbers which you have entered as shown below.

Thus we have created a simple program of Calculator using Ruby on Rails.

You have seen how Ruby on Rails is simple Language to install and also to execute the code. By considering its advantages famous websites such as Twitter, Basecamp, Github, Shopify, Slideshare, etc are also using Ruby on Rails in their programming language to build websites. If you want to learn more about Ruby on Rails visit this link Ruby on Rails.

--

--