| 1 |
#ifndef RBIMPL_INTERN_ENUM_H /*-*-C++-*-vi:se ft=cpp:*/ |
| 2 |
#define RBIMPL_INTERN_ENUM_H |
| 3 |
/** |
| 4 |
* @file |
| 5 |
* @author Ruby developers <[email protected]> |
| 6 |
* @copyright This file is a part of the programming language Ruby. |
| 7 |
* Permission is hereby granted, to either redistribute and/or |
| 8 |
* modify this file, provided that the conditions mentioned in the |
| 9 |
* file COPYING are met. Consult the file for details. |
| 10 |
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are |
| 11 |
* implementation details. Don't take them as canon. They could |
| 12 |
* rapidly appear then vanish. The name (path) of this header file |
| 13 |
* is also an implementation detail. Do not expect it to persist |
| 14 |
* at the place it is now. Developers are free to move it anywhere |
| 15 |
* anytime at will. |
| 16 |
* @note To ruby-core: remember that this header can be possibly |
| 17 |
* recursively included from extension libraries written in C++. |
| 18 |
* Do not expect for instance `__VA_ARGS__` is always available. |
| 19 |
* We assume C99 for ruby itself but we don't assume languages of |
| 20 |
* extension libraries. They could be written in C++98. |
| 21 |
* @brief Public APIs related to ::rb_mEnumerable. |
| 22 |
*/ |
| 23 |
#include "ruby/internal/dllexport.h" |
| 24 |
#include "ruby/internal/value.h" |
| 25 |
|
| 26 |
RBIMPL_SYMBOL_EXPORT_BEGIN() |
| 27 |
|
| 28 |
/* enum.c */ |
| 29 |
|
| 30 |
/** |
| 31 |
* Basically identical to rb_ary_new_form_values(), except it returns something |
| 32 |
* different when `argc` < 2. |
| 33 |
* |
| 34 |
* @param[in] argc Number of objects of `argv`. |
| 35 |
* @param[in] argv Arbitrary objects. |
| 36 |
* @retval RUBY_Qnil `argc` is zero. |
| 37 |
* @retval argv[0] `argc` is one. |
| 38 |
* @retval otherwise Otherwise. |
| 39 |
* |
| 40 |
* @internal |
| 41 |
* |
| 42 |
* What is this business? Well, this function is about `yield`'s taking |
| 43 |
* multiple values. Consider following user-defined class: |
| 44 |
* |
| 45 |
* ```ruby |
| 46 |
* class Foo |
| 47 |
* include Enumerable |
| 48 |
* |
| 49 |
* def each |
| 50 |
* yield :q, :w, :e, :r |
| 51 |
* end |
| 52 |
* end |
| 53 |
* |
| 54 |
* Foo.new.each_with_object([]) do |i, j| |
| 55 |
* j << i # ^^^ <- What to expect for `i`? |
| 56 |
* end |
| 57 |
* ``` |
| 58 |
* |
| 59 |
* Here, `Foo#each_with_object` is in fact `Enumerable#each_with_object`, which |
| 60 |
* doesn't know what would be yielded. Yet, it has to take a block of arity 2. |
| 61 |
* This function is used here, to "pack" arbitrary number of yielded objects |
| 62 |
* into one. |
| 63 |
* |
| 64 |
* If people want to implement their own `Enumerable#each_with_object` this API |
| 65 |
* can be handy. Though @shyouhei suspects it is relatively rare for 3rd party |
| 66 |
* extension libraries to have such things. Also `Enumerable#each_entry` is |
| 67 |
* basically this function exposed as a Ruby method. |
| 68 |
*/ |
| 69 |
VALUE rb_enum_values_pack(int argc, const VALUE *argv); |
| 70 |
|
| 71 |
RBIMPL_SYMBOL_EXPORT_END() |
| 72 |
|
| 73 |
#endif /* RBIMPL_INTERN_ENUM_H */ |