From: Paul Brannan Date: 2007-09-23T21:49:40+09:00 Subject: returning from an iteration loop in an extension How can I write something like this using the C API: def foo(container) container.each do |x| return 42 end end If I write the loop like this: static VALUE iter_i(VALUE sequence) { return rb_funcall(sequence, rb_intern("each"), 0); } static VALUE body_i(VALUE val, VALUE ignore) { /* What to put here? */ } static VALUE foo(VALUE sequence) { rb_iterate(iter_i, sequence, body_i, Qnil); } then I see no good way to pass the return value from body_i into foo. Thus, if I write: class Container def each(&block) block.call(1) block.call(2) block.call(3) return 10 end end then the result should be 42. Ruby sets tag->retval before executing JUMP_TAG, but I see no way to do this with the C API. A similar problem exists with "break". Is it possible to do this or could the C API be modified so it's possible to get the same behavior as in Ruby? Thanks, Paul