Class: Enumerator::Yielder
Instance Method Summary collapse
-
#<<(arg) ⇒ Object
:nodoc:.
-
#initialize ⇒ Object
constructor
:nodoc:.
-
#to_proc ⇒ Object
Returns a Proc object that takes arguments and yields them.
-
#yield(args) ⇒ Object
:nodoc:.
Constructor Details
#initialize ⇒ Object
:nodoc:
1350 1351 1352 1353 1354 1355 1356 |
# File 'enumerator.c', line 1350 static VALUE yielder_initialize(VALUE obj) { rb_need_block(); return yielder_init(obj, rb_block_proc()); } |
Instance Method Details
#<<(arg) ⇒ Object
:nodoc:
1368 1369 1370 1371 1372 1373 1374 1375 1376 |
# File 'enumerator.c', line 1368 static VALUE yielder_yield_push(VALUE obj, VALUE arg) { struct yielder *ptr = yielder_ptr(obj); rb_proc_call_with_block(ptr->proc, 1, &arg, Qnil); return obj; } |
#to_proc ⇒ Object
Returns a Proc object that takes arguments and yields them.
This method is implemented so that a Yielder object can be directly passed to another method as a block argument.
enum = Enumerator.new { |y|
Dir.glob("*.rb") { |file|
File.open(file) { |f| f.each_line(&y) }
}
}
1390 1391 1392 1393 1394 1395 1396 |
# File 'enumerator.c', line 1390 static VALUE yielder_to_proc(VALUE obj) { VALUE method = rb_obj_method(obj, sym_yield); return rb_funcall(method, idTo_proc, 0); } |
#yield(args) ⇒ Object
:nodoc:
1359 1360 1361 1362 1363 1364 1365 |
# File 'enumerator.c', line 1359 static VALUE yielder_yield(VALUE obj, VALUE args) { struct yielder *ptr = yielder_ptr(obj); return rb_proc_call_kw(ptr->proc, args, RB_PASS_CALLED_KEYWORDS); } |