To add two numbers in Ruby, we can simply use the +
operator. The following code demonstrates this:
main.rb59 chars5 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
.
gistlibby LogSnag