Changes

Jump to: navigation, search

Ruby Operators

955 bytes added, 21:15, 15 November 2007
New page: In this chapter we will cover the basics of perfoming mathematical operations in Ruby. == The Anatomy of a Ruby Math Operation == In Ruby, as with most other programming languages, mathe...
In this chapter we will cover the basics of perfoming mathematical operations in Ruby.

== The Anatomy of a Ruby Math Operation ==

In Ruby, as with most other programming languages, mathematical operations consist of values on which the calculation is to be performed (called ''operands'') and an ''operator'' which dictates the mathematical operation to be performed. Typically, the ''operands'' a replaced either side of the ''operator''. Optionally, the ''assignment'' operator (=) can be used to assign the result of the operation to, for example, a variable. Let's take the most basic of operations, executed in ''irb'':

<pre>
irb(main):036:0> 1 + 1
=> 2
irb(main):037:0> result = 1 + 1
=> 2
</pre>

Now let's assign the result to a variable called ''result'':

<pre>
irb(main):037:0> result = 1 + 1
=> 2
</pre>

== Performing Arithmetic using Operators ==

Ruby provides a number of basic operators for performing arithmetic. These are as follows:

Navigation menu