Skip to content

Instantly share code, notes, and snippets.

@zeroeth
Created April 8, 2010 19:56
Show Gist options
  • Save zeroeth/360458 to your computer and use it in GitHub Desktop.
Save zeroeth/360458 to your computer and use it in GitHub Desktop.
/*
* call-seq:
* enum.all? [{|obj| block } ] => true or false
*
* Passes each element of the collection to the given block. The method
* returns <code>true</code> if the block never returns
* <code>false</code> or <code>nil</code>. If the block is not given,
* Ruby adds an implicit block of <code>{|obj| obj}</code> (that is
* <code>all?</code> will return <code>true</code> only if none of the
* collection members are <code>false</code> or <code>nil</code>.)
*
* %w{ ant bear cat}.all? {|word| word.length >= 3} #=> true
* %w{ ant bear cat}.all? {|word| word.length >= 4} #=> false
* [ nil, true, 99 ].all? #=> false
*
*/
static VALUE
enum_all(obj)
VALUE obj;
{
VALUE result = Qtrue;
rb_iterate(rb_each, obj, rb_block_given_p() ? all_iter_i : all_i, (VALUE)&result);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment