Q:

in Ruby, how do I push elements to the end of a range?

Is there any way to push elements onto the end of a range without converting it into an array then back to a range?
r = 1..10
=> 1..10

r << 11
NoMethodError: undefined method `<<' for 1..10:Range

r.push 11
NoMethodError: undefined method `push' for 1..10:Range

A:

A range is simply an interval. A start and an end. You don't just push values on the end of a Range. You either convert the Range to an array
items = range.to_a
items << 11

Or you create a new range.. 
Range.new(range.begin, 11)

EDIT: The reason we use #begin on the range and not #first is because first and last build a new array from the Range, we don't want that.. we just want the begin or end values instead.

A:

You can't. A Range is not an Array, or a Set, or a collection at all really. It's just a representation of an upper and lower bound. You can iterate one because it's possible to step between the upper and lower bounds. You can also turn one into an Array (using Range#to_a), which just iterates and collects the values into an Array.
If you want to expand or shrink the Range, create a new Range based on its #begin and #end.
new_range = Range(old_range.begin, old_range.end + 1)

