Recall & Review
beginner
What does the range operator
.. do in Ruby?The
.. operator creates a range that includes both the start and end values. It's called an inclusive range.Click to reveal answer
beginner
What is the difference between
.. and ... range operators in Ruby?The
.. operator includes the end value in the range (inclusive), while ... excludes the end value (exclusive).Click to reveal answer
beginner
How would you create a range from 1 to 5 excluding 5 in Ruby?
Use the exclusive range operator:
1...5. This includes 1, 2, 3, 4 but not 5.Click to reveal answer
beginner
What will
(1..3).to_a return in Ruby?It returns the array
[1, 2, 3] because the range is inclusive of the end value 3.Click to reveal answer
beginner
What will
(1...3).to_a return in Ruby?It returns the array
[1, 2] because the range excludes the end value 3.Click to reveal answer
Which range operator includes the end value in Ruby?
✗ Incorrect
The
.. operator creates an inclusive range that includes the end value.What does
(5...10).to_a return?✗ Incorrect
The
... operator excludes the end value 10, so the array includes 5 through 9.How do you create a range that includes numbers 1 to 3 in Ruby?
✗ Incorrect
The
.. operator creates an inclusive range including 3.Which of these is an exclusive range in Ruby?
✗ Incorrect
The
... operator excludes the end value, making it exclusive.What will
(10..10).to_a return?✗ Incorrect
An inclusive range from 10 to 10 contains just the number 10.
Explain the difference between the two Ruby range operators
.. and ....Think about whether the last number is part of the range or not.
You got /3 concepts.
How would you use Ruby ranges to create a list of numbers from 1 to 5, excluding 5?
Use the operator that excludes the end value.
You got /3 concepts.