Ruby - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Ruby Operators

Ruby Operators

shape Introduction

This chapter demonstrates about the Ruby Operators which consist of set of operators and those are expect from modern languages and mostly operators just like methods and following are the concepts covered in this chapter.
  • Types Of Operators

Types Of Operators

shape Description

Ruby supports rich set of operators For every operator (+ - * / % ** & | ^ << >> && ||), must have corresponding abbreviated assignment operator like (+= -= etc.) in which some types are listed below. Arithmetic Operators Ruby supports Arithmetic operators which are useful for the Arithmetic operations following are the operators listed below with some explanation.
Operator Description
+ Addition operator can be used to add value to the another side of the operator.
- Subtraction operator which subtract the right side operand with left side operand.
* Multiplication is used to multiply the values on another side of the operator.
/ Division can be used to divide left side operand by right side operand.
% modules can be used to divides the left side operand by right side operands and results the reminder.
Comparison Operators Comparison Operators can be used to compare the both sides operators following are the some comparison  operators listed below.
Operator Description
== Which is used to check whether both operands are equal or not, if yes then condition will be true other wise condition will be false..
!= Which is used to check if the both operands are equal or not, if both values are not equal then condition will be true.
< Which verify if the left operand value is greater then the right operand or not if yes the condition will be true.
> Which verify if the right operand value is greater then left operand or not if yes the condition will be true.
>= Which verify if the left operand value is greater then or equal to the right operand or not if yes the condition becomes true.
<= Which verify if the right operand value is greater then or equal to the left operand or not if yes the condition will be true.
Logical Operators Logical operators are used for logical operations following are some logical operators of ruby listed below.
Operator Description
and Which is logical AND operator if both sides operands are true then only the condition will be true.
or Which is an logical OR operator if any of the both operands or not zero then condition will be true
&& Which is an logical AND operator if two operands are not zero then condition will be true
|| Which is an logical OR operator if any two operands are non zero operands then the condition will be true
not Which is an logical NOT operator is used to reverse the logical state of the operand if condition is true then logical not operator will makes as false.
Assignment Operators Assignment Operators are used to assigning the values to the operators following are the some assignment operators are listed below.
Operator Description
== Which is a simple assignment operator is used to assign values from left hand side to right hand side.
+= Add AND is used to add right side operand to the left side operand and assign result to the left side operand..
-= subtract AND is used to subtract right side operand from the left side operand and assign values to the left side operand.
*= Multiply AND which multiply right side operand with the left side operand and assign values to the left side operand.
/= Divide AND which multiply right side operand with the left side operand and assign values to the left side operand.

Summary

shape Key Points

  • Ruby support rich set of operators.
  • Ruby follows the operator precedence.