static VALUE env_delete_if(VALUE ehash, SEL sel) { RETURN_ENUMERATOR(ehash, 0, 0); env_reject_bang(ehash, 0); return envtbl; }
VALUE _Manager_each(VALUE self) { RETURN_ENUMERATOR(self,0,NULL); for (uint i = 0; i < _manager->getNumAnimations(); ++i) rb_yield(wrap(_manager->getAnimationAtIdx(i))); return self; }
/* * call-seq: * each(*args) -> Enumerator * each(*args) { |item| block } -> Enumerator * * Iterate over the collection, passing each item to a given block. * If no block was supplied, return an enumerator for the collection. * */ static VALUE rbpod_collection_each(VALUE self, VALUE argv) { GList *current = NULL, *collection = TYPED_DATA_PTR(self, GList); VALUE klass, item, arguments; /* Return an enumerator if a block was not supplied. */ RETURN_ENUMERATOR(self, 0, 0); /* What sort of items are we casting this data to? */ klass = rb_funcall(self, rb_intern("type"), 0); /* Create a shallow copy of the passed arguments. */ arguments = rb_ary_dup(argv); /* Prepend an empty element as a placeholder. */ rb_ary_unshift(arguments, Qnil); /* If we were supplied a block, enumerate the entire list. */ for (current = collection; current != NULL; current = g_list_next(current)) { /* TODO: Find a better workaround than this or Data_Wrap_Struct. */ item = rb_class_new_instance_with_data(0, NULL, klass, current->data); rb_ary_store(arguments, 0, item); rb_yield_splat(arguments); } return self; }
VALUE _each(VALUE self) { RETURN_ENUMERATOR(self,0,NULL); for (uint i = 0; i < _self->getNumAffectors(); ++i) rb_yield(wrap( _self->getAffectorAtIdx(i))); return self; }
/* * call-seq: * e.with_object(obj) {|(*args), memo_obj| ... } * e.with_object(obj) * * Iterates the given block for each element with an arbitrary * object given, and returns the initially given object. * * If no block is given, returns an enumerator. * */ static VALUE enumerator_with_object(VALUE obj, SEL sel, VALUE memo) { RETURN_ENUMERATOR(obj, 1, &memo); enumerator_block_call(obj, enumerator_with_object_i, memo); return memo; }
/* * call-seq: * each {|element| } -> self * each -> Enumerator * * interates the child Elements * ===Return value * self */ VALUE _each(VALUE self) { RETURN_ENUMERATOR(self,0,NULL); for (size_t i = 0; i < _self->getChildCount(); ++i) rb_yield(wrap(_self->getChildElementAtIdx(i))); return self; }
/* * call-seq: * Kernel.each_backtrace_frame( & block ) * * Return array of hashes with object and method frame information for backtrace. * Specifying number_of_frames will cause only the last number_of_frames to be returned. * Kernel.backtrace returns all frames including the current context (__method__/__callee__). */ VALUE rb_RPRuby_Sender_Kernel_each_backtrace_frame( int argc, VALUE* args, VALUE rb_self ) { rb_thread_t* c_thread = GET_THREAD(); // Get the current frame - we're doing a backtrace, so our current working frame to start is the first previous thread rb_control_frame_t* c_current_context_frame = RUBY_VM_PREVIOUS_CONTROL_FRAME( RUBY_VM_PREVIOUS_CONTROL_FRAME( c_thread->cfp ) ); // c_top_of_control_frame describes the top edge of the stack trace // set c_top_of_control_frame to the first frame in <main> rb_control_frame_t* c_top_of_control_frame = RUBY_VM_NEXT_CONTROL_FRAME( RUBY_VM_NEXT_CONTROL_FRAME( (void *)( c_thread->stack + c_thread->stack_size ) ) ); VALUE rb_stored_backtrace_array = Qnil; // if we were passed a stored backtrace array, use it if ( argc == 1 && TYPE( args[ 0 ] ) == T_ARRAY ) { rb_stored_backtrace_array = args[ 0 ]; } // for each control frame: while ( c_current_context_frame < c_top_of_control_frame ) { VALUE rb_frame_hash; // if we are using a stored backtrace we don't need to ask for a new hash if ( rb_stored_backtrace_array == Qnil ) { rb_frame_hash = rb_RPRuby_Sender_Kernel_internal_backtraceHashForControlFrame( & c_current_context_frame ); } else { rb_frame_hash = rb_ary_shift( rb_stored_backtrace_array ); } if ( rb_frame_hash == Qnil ) { break; } // if we try to iterate using an Enumerator we will lose our context if ( ! rb_block_given_p() ) { // we solve this by assuming that the desired context is the moment when each_backtrace_frame is called // this allows us to store the backtrace and iterate it as we want // the only downside is that we have to get the entire backtrace first in order to store it rb_stored_backtrace_array = rb_RPRuby_Sender_Kernel_backtrace( 0, NULL, rb_self ); RETURN_ENUMERATOR( rb_self, 1, & rb_stored_backtrace_array ); } // otherwise, yield the block rb_yield( rb_frame_hash ); // only move the frame if we are not using a stored backtrace if ( rb_stored_backtrace_array == Qnil ) { c_current_context_frame = RUBY_VM_PREVIOUS_CONTROL_FRAME( c_current_context_frame ); } } return Qnil; }
/* call-seq: * Etc::Group.each { |group| block } -> obj * Etc::Group.each -> Enumerator * * Iterates for each entry in the /etc/group file if a block is given. * * If no block is given, returns the Enumerator. * * The code block is passed a Group struct. * * Example: * * require 'etc' * * Etc::Group.each {|g| * puts g.name + ": " + g.mem.join(', ') * } * * Etc::Group.collect {|g| g.name} * Etc::Group.select {|g| !g.mem.empty?} * */ static VALUE etc_each_group(VALUE obj) { RETURN_ENUMERATOR(obj, 0, 0); each_group(); return obj; }
static VALUE rb_set_each(VALUE set, SEL sel) { RETURN_ENUMERATOR(set, 0, 0); CFSetApplyFunction((CFMutableSetRef)set, rb_set_each_callback, NULL); return Qnil; }
/* * データベース内のオブジェクトを順番にブロックに渡す。 * * @example すべてのオブジェクトの名前を表示する: * database.each do |object| * p object.name * end * * @example すべてのオブジェクトの名前をID順で表示する: * database.each(:order_by => :id) do |object| * p object.name * end * * @example すべてのオブジェクトの名前をキー名の降順で表示する: * database.each(:order_by => :key, :order => :desc) do |object| * p object.name * end * * @overload each(options=nil) * @macro [new] database.each.options * @param options [::Hash] * @yield [object] * @option options :order * +:asc+ または +:ascending+ を指定すると昇順にレコードを取 * り出す。(デフォルト) * +:desc+ または +:descending+ を指定すると降順にレコードを * 取り出す。 * @option options :order_by (:key) * +:id+ を指定するとID順にレコードを取り出す。 * +:key+ 指定するとキー順にレコードを取り出す。(デフォル * ト) * @macro database.each.options * * @overload each(options=nil) * @macro database.each.options * @option options :ignore_missing_object (false) * Specify +true+ to ignore missing object. Otherwise, an exception is * raised for missing object. * * @since 2.0.5 */ static VALUE rb_grn_database_each (int argc, VALUE *argv, VALUE self) { grn_ctx *context = NULL; grn_obj *database; grn_table_cursor *cursor; VALUE rb_cursor, rb_options, rb_order, rb_order_by; VALUE rb_ignore_missing_object; int flags = 0; grn_id id; VALUE exception; RETURN_ENUMERATOR(self, argc, argv); rb_grn_database_deconstruct(SELF(self), &database, &context, NULL, NULL, NULL, NULL); rb_scan_args(argc, argv, "01", &rb_options); rb_grn_scan_options(rb_options, "order", &rb_order, "order_by", &rb_order_by, "ignore_missing_object", &rb_ignore_missing_object, NULL); flags |= rb_grn_table_cursor_order_to_flag(rb_order); flags |= rb_grn_table_cursor_order_by_to_flag(GRN_TABLE_PAT_KEY, self, rb_order_by); cursor = grn_table_cursor_open(context, database, NULL, 0, NULL, 0, 0, -1, flags); rb_cursor = GRNTABLECURSOR2RVAL(Qnil, context, cursor); rb_iv_set(self, "cursor", rb_cursor); while ((id = grn_table_cursor_next(context, cursor)) != GRN_ID_NIL) { grn_obj *object; object = grn_ctx_at(context, id); if (!object && RTEST(rb_ignore_missing_object)) { context->rc = GRN_SUCCESS; continue; } exception = rb_grn_context_to_exception(context, self); if (!NIL_P(exception)) { rb_grn_object_close(rb_cursor); rb_iv_set(self, "cursor", Qnil); rb_exc_raise(exception); } if (object) { rb_yield(GRNOBJECT2RVAL(Qnil, context, object, GRN_FALSE)); } } rb_grn_object_close(rb_cursor); rb_iv_set(self, "cursor", Qnil); return Qnil; }
VALUE _Manager_each(VALUE self) { RETURN_ENUMERATOR(self,0,NULL); //check if system is created wrap< CEGUI::System* >(self); wrap_each(_manager->getIterator()); return self; }
VALUE _each_child(VALUE self) { RETURN_ENUMERATOR(self,0,NULL); size_t count = _self->GetChildCount(); for(size_t i = 0; i < count; ++i) rb_yield(wrap(_self->Item(i))); return self; }
VALUE _Manager_each_falagard(VALUE self) { RETURN_ENUMERATOR(self,0,NULL); //check if system is created wrap< CEGUI::System* >(self); wrap_each(_factorymanager->getFalagardMappingIterator()); return self; }
static VALUE rhash_each_pair(VALUE hash, SEL sel) { RETURN_ENUMERATOR(hash, 0, 0); rhash_foreach(hash, each_pair_i, 0); RETURN_IF_BROKEN(); return hash; }
VALUE rhash_keep_if(VALUE hash, SEL sel) { RETURN_ENUMERATOR(hash, 0, 0); rhash_modify(hash); rhash_foreach(hash, keep_if_i, hash); return hash; }
static VALUE rhash_reject_bang(VALUE hash, SEL sel) { RETURN_ENUMERATOR(hash, 0, 0); const long n = rhash_len(hash); rhash_delete_if(hash, 0); return n == rhash_len(hash) ? Qnil : hash; }
/* * call-seq: * each_with_object(obj) {|(*args), memo_obj| ... } * each_with_object(obj) * * Iterates the given block for each element with an arbitrary * object given, and returns the initially given object. * If no block is given, returns an enumerator. * * e.g.: * evens = (1..10).each_with_object([]) {|i, a| a << i*2 } * # => [2, 4, 6, 8, 10, 12, 14, 16, 18, 20] * */ static VALUE enum_each_with_object(VALUE obj, VALUE memo) { RETURN_ENUMERATOR(obj, 1, &memo); rb_block_call(obj, SYM2ID(sym_each), 0, 0, each_with_object_i, memo); return memo; }
VALUE _each(VALUE self) { RETURN_ENUMERATOR(self,0,NULL); for (unsigned int i = 0; i < _self->getNumPoints(); ++i) { rb_yield(wrap(_self->getPoint(i))); } return self; }
/* call-seq: * Etc::Passwd.each { |struct| block } -> Passwd * Etc::Passwd.each -> Enumerator * * Iterates for each entry in the /etc/passwd file if a block is given. * * If no block is given, returns the Enumerator. * * The code block is passed an Passwd struct. * * See ::getpwent above for details. * * Example: * * require 'etc' * * Etc::Passwd.each {|u| * puts u.name + " = " + u.gecos * } * * Etc::Passwd.collect {|u| u.gecos} * Etc::Passwd.collect {|u| u.gecos} * */ static VALUE etc_each_passwd(VALUE obj) { #ifdef HAVE_GETPWENT RETURN_ENUMERATOR(obj, 0, 0); each_passwd(); #endif return obj; }
VALUE _each_item(VALUE self) { RETURN_ENUMERATOR(self,0,NULL); for (unsigned int i = 0; i < _self->getItemCount(); ++i) { rb_yield(wrap(_self->getListboxItemFromIndex(i))); } return self; }
static VALUE rhash_select(VALUE hash, SEL sel) { RETURN_ENUMERATOR(hash, 0, 0); VALUE result = rb_hash_new(); rhash_foreach(hash, select_i, result); RETURN_IF_BROKEN(); return result; }
/* * call-seq: * e.with_index(offset = 0) {|(*args), idx| ... } * e.with_index(offset = 0) * * Iterates the given block for each element with an index, which * starts from +offset+. If no block is given, returns a new Enumerator * that includes the index, starting from +offset+ * * +offset+:: the starting index to use * */ static VALUE enumerator_with_index(int argc, VALUE *argv, VALUE obj) { VALUE memo; rb_scan_args(argc, argv, "01", &memo); RETURN_ENUMERATOR(obj, argc, argv); memo = NIL_P(memo) ? 0 : (VALUE)NUM2LONG(memo); return enumerator_block_call(obj, enumerator_with_index_i, (VALUE)&memo); }
static VALUE rhash_select_bang(VALUE hash, SEL sel) { RETURN_ENUMERATOR(hash, 0, 0); rhash_modify(hash); const long n = rhash_len(hash); rb_hash_foreach(hash, keep_if_i, hash); RETURN_IF_BROKEN(); return n == rhash_len(hash) ? Qnil : hash; }
static VALUE env_each_value(VALUE ehash, SEL sel) { RETURN_ENUMERATOR(ehash, 0, 0); VALUE values = env_values(Qnil, 0); /* rb_secure(4); */ for (long i = 0, count = RARRAY_LEN(values); i < count; i++) { rb_yield(RARRAY_AT(values, i)); RETURN_IF_BROKEN(); } return ehash; }
/* @overload each_word{ |word| … } * * Enumerates the words in the receiver, each inheriting any taint and * untrust. * * @yieldparam [U::String] word * @return [self] * @see http://www.unicode.org/reports/tr29/ * Unicode Standard Annex #29: Unicode Text Segmentation * * @overload each_word * * @return [Enumerator] An Enumerator over the characters in the receiver * @see http://www.unicode.org/reports/tr29/ * Unicode Standard Annex #29: Unicode Text Segmentation */ VALUE rb_u_string_each_word(VALUE self) { RETURN_ENUMERATOR(self, 0, NULL); const struct rb_u_string *string = RVAL2USTRING(self); const char *p = USTRING_STR(string); size_t length = USTRING_LENGTH(string); u_words(p, length, (u_substring_fn)each, &self); return self; }
VALUE _each(VALUE self) { RETURN_ENUMERATOR(self,0,NULL); for(unsigned int i = 0;i<CEGUI::FIC_FRAME_IMAGE_COUNT;++i) { const CEGUI::Image *image = _self->getImage((CEGUI::FrameImageComponent)i); if(image) rb_yield_values(2,wrap((CEGUI::FrameImageComponent)i),wrap(image)); } return self; }
static VALUE rb_struct_each(VALUE s) { long i; RETURN_ENUMERATOR(s, 0, 0); for (i=0; i<RSTRUCT(s)->len; i++) { rb_yield(RSTRUCT(s)->ptr[i]); } return s; }
static VALUE rb_struct_each(VALUE s) { long i; RETURN_ENUMERATOR(s, 0, 0); for (i=0; i<RSTRUCT_LEN(s); i++) { rb_yield(RSTRUCT_PTR(s)[i]); } return s; }
/* * call-seq: * type_array.each {|item| block } => TypeArray * * Calls <i>block</i> once for each element in <i>self</i>, passing that element as a parameter. * * === Examples * buf = ArrayBuffer.new(16) => ArrayBuffer * * ary = Int32Array.new(buf) => Int32Array * ary[0] = 2 => nil * ary[1] = 4 => nil * ary[2] = 8 => nil * ary[3] = 16 => nil * * ary.map(&:to_s) => %w(2 4 8 16) * */ static VALUE rb_type_array_each(VALUE obj) { long index; GetTypeArray(obj); GetArrayBuffer(ary->buf); RETURN_ENUMERATOR(obj, 0, 0); for (index = 0; index < ary->length; index++) { rb_yield(ary->aref_fn(buf->buf, (index * ary->size))); } return obj; }
/* * call-seq: * buf.each {|frame| block } => buf * buf.each => anEnumerator * * Iterates through each frame in the buffer. Each frame is either a number or * an array of numbers if there are multiple channels. */ static VALUE ra_buffer_each(VALUE self) { RA_BUFFER *buf; Data_Get_Struct(self, RA_BUFFER, buf); RETURN_ENUMERATOR(self, 0, 0); long i; for(i = 0; i < buf->real_size; i++) { rb_yield(ra_buffer_aref(self, LONG2FIX(i))); } return self; }