add two numbers in ruby

To add two numbers in Ruby, we can simply use the + operator. The following code demonstrates this:

main.rb
num1 = 5
num2 = 10
sum = num1 + num2
puts sum # outputs 15
59 chars
5 lines

In the code above, we first define two variables num1 and num2 with values of 5 and 10, respectively. We then add these two variables together using the + operator and store the result in a third variable called sum. Finally, we use the puts method to output the value of sum to the console, which prints 15.

related categories

gistlibby LogSnag