W3cubDocs

/Ruby 3

class Enumerator::Yielder

Parent:
Object

Yielder

Public Instance Methods

to_proc() Show source
static VALUE
yielder_to_proc(VALUE obj)
{
    VALUE method = rb_obj_method(obj, sym_yield);

    return rb_funcall(method, idTo_proc, 0);
}

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) }
  }
}

Ruby Core © 1993–2020 Yukihiro Matsumoto
Licensed under the Ruby License.
Ruby Standard Library © contributors
Licensed under their own licenses.