Ruby
3.4.0dev (2024-11-05 revision 348a53415339076afc4a02fcd09f3ae36e9c4c61)
|
Public APIs related to rb_cEnumerator. More...
#include "ruby/internal/attr/nonnull.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/intern/eval.h"
#include "ruby/internal/iterator.h"
#include "ruby/internal/symbol.h"
#include "ruby/internal/value.h"
Go to the source code of this file.
Data Structures | |
struct | rb_arithmetic_sequence_components_t |
Decomposed Enumerator::ArithmeicSequence . More... | |
Macros | |
#define | SIZED_ENUMERATOR(obj, argc, argv, size_fn) |
This is an implementation detail of RETURN_SIZED_ENUMERATOR(). More... | |
#define | SIZED_ENUMERATOR_KW(obj, argc, argv, size_fn, kw_splat) |
This is an implementation detail of RETURN_SIZED_ENUMERATOR_KW(). More... | |
#define | RETURN_SIZED_ENUMERATOR(obj, argc, argv, size_fn) |
This roughly resembles return enum_for(__callee__) unless block_given? . More... | |
#define | RETURN_SIZED_ENUMERATOR_KW(obj, argc, argv, size_fn, kw_splat) |
Identical to RETURN_SIZED_ENUMERATOR(), except you can specify how to handle the last element of the given array. More... | |
#define | RETURN_ENUMERATOR(obj, argc, argv) RETURN_SIZED_ENUMERATOR(obj, argc, argv, 0) |
Identical to RETURN_SIZED_ENUMERATOR(), except its size is unknown. More... | |
#define | RETURN_ENUMERATOR_KW(obj, argc, argv, kw_splat) RETURN_SIZED_ENUMERATOR_KW(obj, argc, argv, 0, kw_splat) |
Identical to RETURN_SIZED_ENUMERATOR_KW(), except its size is unknown. More... | |
Typedefs | |
typedef VALUE | rb_enumerator_size_func(VALUE recv, VALUE argv, VALUE eobj) |
This is the type of functions that rb_enumeratorize_with_size() expects. More... | |
Functions | |
VALUE | rb_enumeratorize (VALUE recv, VALUE meth, int argc, const VALUE *argv) |
Constructs an enumerator. More... | |
VALUE | rb_enumeratorize_with_size (VALUE recv, VALUE meth, int argc, const VALUE *argv, rb_enumerator_size_func *func) |
Identical to rb_enumeratorize(), except you can additionally specify the size function of return value. More... | |
VALUE | rb_enumeratorize_with_size_kw (VALUE recv, VALUE meth, int argc, const VALUE *argv, rb_enumerator_size_func *func, int kw_splat) |
Identical to rb_enumeratorize_with_func(), except you can specify how to handle the last element of the given array. More... | |
int | rb_arithmetic_sequence_extract (VALUE as, rb_arithmetic_sequence_components_t *buf) |
Extracts components of the passed arithmetic sequence. More... | |
VALUE | rb_arithmetic_sequence_beg_len_step (VALUE as, long *begp, long *lenp, long *stepp, long len, int err) |
Identical to rb_range_beg_len(), except it takes an instance of Enumerator::ArithmericSequence . More... | |
Public APIs related to rb_cEnumerator.
RBIMPL
or rbimpl
are implementation details. Don't take them as canon. They could rapidly appear then vanish. The name (path) of this header file is also an implementation detail. Do not expect it to persist at the place it is now. Developers are free to move it anywhere anytime at will. __VA_ARGS__
is always available. We assume C99 for ruby itself but we don't assume languages of extension libraries. They could be written in C++98. Definition in file enumerator.h.
#define RETURN_ENUMERATOR | ( | obj, | |
argc, | |||
argv | |||
) | RETURN_SIZED_ENUMERATOR(obj, argc, argv, 0) |
Identical to RETURN_SIZED_ENUMERATOR(), except its size is unknown.
[in] | obj | A receiver. |
[in] | argc | Number of objects of argv . |
[in] | argv | Arguments passed to the current method. |
Definition at line 239 of file enumerator.h.
#define RETURN_ENUMERATOR_KW | ( | obj, | |
argc, | |||
argv, | |||
kw_splat | |||
) | RETURN_SIZED_ENUMERATOR_KW(obj, argc, argv, 0, kw_splat) |
Identical to RETURN_SIZED_ENUMERATOR_KW(), except its size is unknown.
It can also be seen as a routine identical to RETURN_ENUMERATOR(), except you can specify how to handle the last element of the given array.
[in] | obj | A receiver. |
[in] | argc | Number of objects of argv . |
[in] | argv | Arguments passed to the current method. |
[in] | kw_splat | Handling of keyword parameters:
|
Definition at line 256 of file enumerator.h.
#define RETURN_SIZED_ENUMERATOR | ( | obj, | |
argc, | |||
argv, | |||
size_fn | |||
) |
This roughly resembles return enum_for(__callee__) unless block_given?
.
[in] | obj | A receiver. |
[in] | argc | Number of objects of argv . |
[in] | argv | Arguments passed to the current method. |
[in] | size_fn | Size calculator. |
Definition at line 206 of file enumerator.h.
#define RETURN_SIZED_ENUMERATOR_KW | ( | obj, | |
argc, | |||
argv, | |||
size_fn, | |||
kw_splat | |||
) |
Identical to RETURN_SIZED_ENUMERATOR(), except you can specify how to handle the last element of the given array.
[in] | obj | A receiver. |
[in] | argc | Number of objects of argv . |
[in] | argv | Arguments passed to the current method. |
[in] | size_fn | Size calculator. |
[in] | kw_splat | Handling of keyword parameters:
|
Definition at line 226 of file enumerator.h.
#define SIZED_ENUMERATOR | ( | obj, | |
argc, | |||
argv, | |||
size_fn | |||
) |
This is an implementation detail of RETURN_SIZED_ENUMERATOR().
You could use it directly, but can hardly be handy.
[in] | obj | A receiver. |
[in] | argc | Number of objects of argv . |
[in] | argv | Arguments passed to the current method. |
[in] | size_fn | Size calculator. |
recv
with argv
. Definition at line 174 of file enumerator.h.
#define SIZED_ENUMERATOR_KW | ( | obj, | |
argc, | |||
argv, | |||
size_fn, | |||
kw_splat | |||
) |
This is an implementation detail of RETURN_SIZED_ENUMERATOR_KW().
You could use it directly, but can hardly be handy.
[in] | obj | A receiver. |
[in] | argc | Number of objects of argv . |
[in] | argv | Arguments passed to the current method. |
[in] | size_fn | Size calculator. |
[in] | kw_splat | Handling of keyword parameters:
|
recv
with argv
. Definition at line 193 of file enumerator.h.
This is the type of functions that rb_enumeratorize_with_size() expects.
In theory an enumerator can have indefinite number of elements, but in practice it often is the case we can compute the size of an enumerator beforehand. If your enumerator has such property, supply a function that calculates such values.
[in] | recv | The original receiver of the enumerator. |
[in] | argv | Arguments passed to Object#enum_for etc. |
[in] | eobj | The enumerator object. |
eobj
, in rb_cNumeric, or RUBY_Qnil if the size is not known until we actually iterate. Definition at line 45 of file enumerator.h.
VALUE rb_arithmetic_sequence_beg_len_step | ( | VALUE | as, |
long * | begp, | ||
long * | lenp, | ||
long * | stepp, | ||
long | len, | ||
int | err | ||
) |
Identical to rb_range_beg_len(), except it takes an instance of Enumerator::ArithmericSequence
.
[in] | as | An Enumerator::ArithmericSequence instance. |
[out] | begp | Return value buffer. |
[out] | lenp | Return value buffer. |
[out] | stepp | Return value buffer. |
[in] | len | Updated length. |
[in] | err | In case len is out of range...
|
rb_eRangeError | as cannot fit into long . |
RUBY_Qfalse | as is not Enumerator::ArithmericSequence . |
RUBY_Qnil | len is out of as but err is zero. |
RUBY_Qtrue | Otherwise. |
beg
is the (possibly updated) left endpoint. len
is the (possibly updated) length of the range. Definition at line 3848 of file enumerator.c.
int rb_arithmetic_sequence_extract | ( | VALUE | as, |
rb_arithmetic_sequence_components_t * | buf | ||
) |
Extracts components of the passed arithmetic sequence.
This can be seen as an extended version of rb_range_values().
[in] | as | Target instance of Enumerator::ArithmericSequence . |
[out] | buf | Decomposed results buffer. |
as
is not Enumerator::ArithmericSequence
. buf
is filled. Definition at line 3830 of file enumerator.c.
Constructs an enumerator.
This roughly resembles Object#enum_for
.
[in] | recv | A receiver of meth . |
[in] | meth | Method ID in a symbol object. |
[in] | argc | Number of objects of argv . |
[in] | argv | Arguments passed to meth . |
rb_eTypeError | meth is not an instance of rb_cSymbol. |
meth
on recv
with argv
. Definition at line 524 of file enumerator.c.
VALUE rb_enumeratorize_with_size | ( | VALUE | recv, |
VALUE | meth, | ||
int | argc, | ||
const VALUE * | argv, | ||
rb_enumerator_size_func * | func | ||
) |
Identical to rb_enumeratorize(), except you can additionally specify the size function of return value.
[in] | recv | A receiver of meth . |
[in] | meth | Method ID in a symbol object. |
[in] | argc | Number of objects of argv . |
[in] | argv | Arguments passed to meth . |
[in] | func | Size calculator. |
rb_eTypeError | meth is not an instance of rb_cSymbol. |
meth
on recv
with argv
. func
can be zero, which means the size is unknown. Definition at line 549 of file enumerator.c.
Referenced by rb_enumeratorize().
VALUE rb_enumeratorize_with_size_kw | ( | VALUE | recv, |
VALUE | meth, | ||
int | argc, | ||
const VALUE * | argv, | ||
rb_enumerator_size_func * | func, | ||
int | kw_splat | ||
) |
Identical to rb_enumeratorize_with_func(), except you can specify how to handle the last element of the given array.
[in] | recv | A receiver of meth . |
[in] | meth | Method ID in a symbol object. |
[in] | argc | Number of objects of argv . |
[in] | argv | Arguments passed to meth . |
[in] | func | Size calculator. |
[in] | kw_splat | Handling of keyword parameters:
|
rb_eTypeError | meth is not an instance of rb_cSymbol. |
meth
on recv
with argv
. func
can be zero, which means the size is unknown. Definition at line 533 of file enumerator.c.
Referenced by rb_enumeratorize_with_size().