Method: Range#size

Defined in:
range.c

#sizeNumeric

Returns the number of elements in the range. Both the begin and the end of the Range must be Numeric, otherwise nil is returned.

(10..20).size    #=> 11
('a'..'z').size  #=> nil
(-Float::INFINITY..Float::INFINITY).size #=> Infinity

Returns:



715
716
717
718
719
720
721
722
723
# File 'range.c', line 715

static VALUE
range_size(VALUE range)
{
    VALUE b = RANGE_BEG(range), e = RANGE_END(range);
    if (rb_obj_is_kind_of(b, rb_cNumeric) && rb_obj_is_kind_of(e, rb_cNumeric)) {
	return ruby_num_interval_step_size(b, e, INT2FIX(1), EXCL(range));
    }
    return Qnil;
}