Interactive Ruby
2 min readMay 22, 2023
Ruby offers easy-to-use interactive functionality, which is referred to as interactive ruby. (IRB).
irb
3.0.0 :001 > puts "Hi!"
Hi!
=> nil
3.0.0 :002 > print "Hi!"
Hi! => nil
99**45
=> 636185486063871224577278269599438356286750793148313662587196470579383532879142704680104499
The large operation can easily manipulate using the ruby.
Some Math Operations:
- Adds numbers: +
25+26
=> 51
- Subtracts the number from another number: -
59-25
=> 34
- Divide the number with another number: /
65/5
=> 13
- Multiply two numbers: *
84*45
=> 3780
- Finds a number raised to the power of another: **
89**2
=> 7921
- Findings: the remainder: %
99%2
=> 1
- Adds and assigns a value to a variable: +=
a = 0
=> 0
3.0.0 :012 > a += 25
=> 25
- Subtracts and assigns a value to a variable: -=
b = 20
=> 20
3.0.0 :014 > b -= 5
=> 15
- Multiply and assigns a value to a variable: *=
c = 8
=> 8
3.0.0 :016 > c *= 2
=> 16
- Divides and assigns a value to a variable: /=
d = 15
=> 15
3.0.0 :021 > d /= 5
=> 3
- Finds the remainder and assigns it to a variable: %=
e = 75
=> 75
3.0.0 :023 > e %= 10
=> 5
Space doesn’t matter:
5 + 3
=> 8
Decimals:
Ruby must perform a floating-point or decimal calculation rather than an integer one.
10/3
=> 3
3.0.0 :027 > 10.0/3
=> 3.3333333333333335