take_while()
public
Passes elements to the block until the block returns nil or false, then
stops iterating and returns an array of all prior elements.
a = [1, 2, 3, 4, 5, 0]
a.take_while {|i| i < 3 }
Show source
/*
* call-seq:
* enum.take_while {|arr| block } => array
*
* Passes elements to the block until the block returns nil or false,
* then stops iterating and returns an array of all prior elements.
*
* a = [1, 2, 3, 4, 5, 0]
* a.take_while {|i| i < 3 } # => [1, 2]
*
*/
static VALUE
enum_take_while(obj)
VALUE obj;
{
VALUE ary;
RETURN_ENUMERATOR(obj, 0, 0);
ary = rb_ary_new();
rb_block_call(obj, id_each, 0, 0, take_while_i, (VALUE)&ary);
return ary;
}