APIdock / Ruby
/
method

first

ruby latest stable - Class: Range
first(p1)
public

Returns the first object in the range, or an array of the first n elements.

(10..20).first  #=> 10
(10..20).first (3) #=> [10, 11, 12]
static VALUE
range_first(int argc, VALUE *argv, VALUE range)
{
 VALUE n, ary[2];
 if (argc == 0) return RANGE_BEG(range);
 rb_scan_args(argc, argv, "1", &n);
 ary[0] = n;
 ary[1] = rb_ary_new2(NUM2LONG(n));
 rb_block_call(range, idEach, 0, 0, first_i, (VALUE)ary);
 return ary[1];
}

AltStyle によって変換されたページ (->オリジナル) /