Ruby Basic Exercises: Compute the sum of the two integers
Write a Ruby program to compute the sum of the two integers, if the two values are equal return double their sum otherwise return their sum.

Ruby Code:
def sum_double(x, y)
x == y ? (x+y)*2 : x+y
end
print sum_double(5, 5),"\n"
print sum_double(4, 5)
Output:
20 9
Flowchart:

Ruby Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Ruby program to check if a number is within 10 of 100 or 200.
Next: Write a Ruby program to print "Ruby Basic Exercises" 9 times.
What is the difficulty level of this exercise?
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics