method
size
ruby latest stable - Class:
Range
size()public
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
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;
}