class method
Range.new
[out Elem] (Elem from, Elem to, ?::boolish exclude_end) -> ::Range[Elem]
Range.new(begin, end, exclude_end = false) → new_range
range.c
View on GitHub ↗
static VALUE
range_initialize(int argc, VALUE *argv, VALUE range)
{
VALUE beg, end, flags;
rb_scan_args(argc, argv, "21", &beg, &end, &flags);
range_modify(range);
range_init(range, beg, end, RBOOL(RTEST(flags)));
return Qnil;
}
Returns a new range based on the given objects begin and end. Optional argument exclude_end determines whether object end is included as the last object in the range:
Example
Range.new(2, 5).to_a # => [2, 3, 4, 5] Range.new(2, 5, true).to_a # => [2, 3, 4] Range.new('a', 'd').to_a # => ["a", "b", "c", "d"] Range.new('a', 'd', true).to_a # => ["a", "b", "c"]