Addition(+)
Adds values on either side of the operator.
Example
puts ("Addition of 5 and 6 is")
puts(5 + 6)
puts ("Addition of 11 and 2 is")
puts(11 + 2)

You can also try this code with Online Ruby Compiler
Run Code
Output
Addition of 5 and 6 is
11
Addition of 11 and 2 is
13

You can also try this code with Online Ruby Compiler
Run Code
Subtraction(-)
Subtracts right hand operand from left-hand operand.
Example
puts ("Subtraction of 11 and 2 is")
puts(11 - 2)
puts ("Subtraction of 8 and 4 is")
puts(8 - 4)

You can also try this code with Online Ruby Compiler
Run Code
Output
Subtraction of 11 and 2 is
9
Subtraction of 8 and 4 is
4

You can also try this code with Online Ruby Compiler
Run Code
Multiplication(*)
Multiplies operands value on either side of the operator.
Example
puts ("Multiplication of 11 and 2 is")
puts(11 * 2)
puts ("Multiplication of 8 and 4 is")
puts(8 * 4)

You can also try this code with Online Ruby Compiler
Run Code
Output
Multiplication of 11 and 2 is
22
Multiplication of 8 and 4 is
32

You can also try this code with Online Ruby Compiler
Run Code
Division(/)
Divides left hand operand by right hand operand.
Example
puts ("Division of 12 and 2 is")
puts(12/ 2)
puts ("Division of 8 and 4 is")
puts(8 / 4)

You can also try this code with Online Ruby Compiler
Run Code
Output
Division of 12 and 2 is
6
Division of 8 and 4 is
2

You can also try this code with Online Ruby Compiler
Run Code
Modulus(%)
Divides left hand operand by right hand operand and return the remainder.
Example
puts ("Modulus of 11 and 2 is")
puts(11 % 2)
puts ("Modulus of 8 and 3 is")
puts(8 % 3)

You can also try this code with Online Ruby Compiler
Run Code
Output
Modulus of 11 and 2 is
1
Modulus of 8 and 3 is
2

You can also try this code with Online Ruby Compiler
Run Code
Frequently Asked Questions
What does Ruby's |= stand for?
It's short for or-equals-to. It first checks whether the value on the left is defined, after which it uses it. If it isn't, use the right-hand value.
In Ruby, what is a lambda?
A lambda is a Ruby object that is comparable to a proc. A lambda, unlike a proc, requires a fixed number of arguments to be supplied to it, and instead of returning immediately, it returns s to its calling procedure.
In Ruby, what is self?
self is a unique variable that refers to the object that "owns" the code that is now running.
In Ruby, what is yield?
Yield is a Ruby keyword that allows a developer to give an argument to a block. The amount of arguments that can be passed to the block is unlimited.
Conclusion
We've covered a lot of topics in this post about arithmetic operators and how they're implemented in Ruby. We looked at addition, subtraction, multiplication, division, and modulus operators in depth using examples.
We hope this article helps you to learn something new. And if you're interested in learning more, see our posts on 8 reasons why Ruby should be your first language!, Ruby, Introduction to Ruby on Rails, Ruby on rails for your next web development project!, Ruby on Rails.
To learn more about Micro Operations, refer to Arithmetic Micro Operations.
Visit our practice platform Coding Ninjas Studio to practice top problems, attempt mock tests, read interview experiences, and much more.!
Thank you for reading this post :-)
Feel free to upvote and share this article if it has been useful for you.