Ruby Range

Tonja Daniels
TonjaGraphix
Published in
2 min readJun 10, 2018

Something I learned today! The Ruby range.

Range represents a set of values that has a beginning an an ending, i.e., 1- 4, A-Z. When writing code, ranges are constructed with two periods “..”, these periods tell the computer to consider all items between two numbers or two letters that are sequential. See the example below.

You can also use 3 periods “…”, however, keep in mind that it will omit the last item that you have list. See example below.

As you can see, in the 3rd line on the right, the letter “f” has been omitted.

You can also add all the numbers in the range and get the sum output by adding “.sum” at the end. See the example below.

See the answers on the right on lines 1 and 2.

Anyway, I hope you all enjoyed this little bit of info using Ruby!

--

--