Ruby 3.4.5p51 (2025-07-16 revision 20cda200d3ce092571d0b5d342dadca69636cb0f)
|
Public APIs related to rb_cStruct. More...
#include "ruby/internal/attr/nonnull.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/intern/vm.h"
#include "ruby/internal/value.h"
Go to the source code of this file.
Functions | |
VALUE | rb_struct_new (VALUE klass,...) |
Creates an instance of the given struct. | |
VALUE | rb_struct_define (const char *name,...) |
Defines a struct class. | |
VALUE | rb_struct_define_under (VALUE space, const char *name,...) |
Identical to rb_struct_define(), except it defines the class under the specified namespace instead of global toplevel. | |
VALUE | rb_struct_alloc (VALUE klass, VALUE values) |
Identical to rb_struct_new(), except it takes the field values as a Ruby array. | |
VALUE | rb_struct_initialize (VALUE self, VALUE values) |
Mass-assigns a struct's fields. | |
VALUE | rb_struct_getmember (VALUE self, ID key) |
Identical to rb_struct_aref(), except it takes ID instead of VALUE. | |
VALUE | rb_struct_s_members (VALUE klass) |
Queries the list of the names of the fields of the given struct class. | |
VALUE | rb_struct_members (VALUE self) |
Queries the list of the names of the fields of the class of the given struct object. | |
VALUE | rb_struct_alloc_noinit (VALUE klass) |
Allocates an instance of the given class. | |
VALUE | rb_struct_define_without_accessor (const char *name, VALUE super, rb_alloc_func_t func,...) |
Identical to rb_struct_define(), except it does not define accessor methods. | |
VALUE | rb_struct_define_without_accessor_under (VALUE outer, const char *class_name, VALUE super, rb_alloc_func_t alloc,...) |
Identical to rb_struct_define_without_accessor(), except it defines the class under the specified namespace instead of global toplevel. | |
VALUE | rb_data_define (VALUE super,...) |
Defines an anonymous data class. |
Public APIs related to rb_cStruct.
Definition in file struct.h.
Defines an anonymous data class.
[in] | super | Superclass of the defining class. Must be a descendant of ::rb_cData, or 0 as ::rb_cData. |
[in] | ... | Arbitrary number of const char*, terminated by NULL. Each of which are the name of fields. |
rb_eArgError | Duplicated field name. |
Definition at line 1700 of file struct.c.
Referenced by rb_data_define().
Identical to rb_struct_new(), except it takes the field values as a Ruby array.
[in] | klass | The class of the instance to allocate. |
[in] | values | Field values. |
Definition at line 837 of file struct.c.
Referenced by rb_struct_alloc().
Allocates an instance of the given class.
This consequential name is of course because rb_struct_alloc() not only allocates but also initialises an instance. The API design is broken.
[in] | klass | A subclass of rb_cStruct. |
Definition at line 406 of file struct.c.
Referenced by rb_struct_alloc_noinit().
VALUE rb_struct_define | ( | const char * | name, |
... ) |
Defines a struct class.
[in] | name | Name of the class. |
[in] | ... | Arbitrary number of const char*, terminated by NULL. Each of which are the name of fields. |
rb_eNameError | `name` is not a constant name. |
rb_eTypeError | `name` is already taken. |
rb_eArgError | Duplicated field name. |
Definition at line 486 of file struct.c.
Referenced by rb_struct_define().
Identical to rb_struct_define(), except it defines the class under the specified namespace instead of global toplevel.
[out] | space | Namespace that the defining class shall reside. |
[in] | name | Name of the class. |
[in] | ... | Arbitrary number of const char*, terminated by NULL. Each of which are the name of fields. |
rb_eNameError | `name` is not a constant name. |
rb_eTypeError | `name` is already taken. |
rb_eArgError | Duplicated field name. |
Definition at line 506 of file struct.c.
Referenced by rb_struct_define_under().
VALUE rb_struct_define_without_accessor | ( | const char * | name, |
VALUE | super, | ||
rb_alloc_func_t | func, | ||
... ) |
Identical to rb_struct_define(), except it does not define accessor methods.
You have to define them yourself. Forget about the allocator function parameter; it is for internal use only. Extension libraries are unable to properly allocate a ruby struct, because RStruct is opaque.
[in] | name | Name of the class. |
[in] | super | Superclass of the defining class. |
[in] | func | Must be 0 for extension libraries. |
[in] | ... | Arbitrary number of const char*, terminated by NULL. Each of which are the name of fields. |
rb_eNameError | `name` is not a constant name. |
rb_eTypeError | `name` is already taken. |
rb_eArgError | Duplicated field name. |
Definition at line 473 of file struct.c.
Referenced by rb_struct_define_without_accessor().
VALUE rb_struct_define_without_accessor_under | ( | VALUE | outer, |
const char * | class_name, | ||
VALUE | super, | ||
rb_alloc_func_t | alloc, | ||
... ) |
Identical to rb_struct_define_without_accessor(), except it defines the class under the specified namespace instead of global toplevel.
It can also be seen as a routine identical to rb_struct_define_under(), except it does not define accessor methods.
[out] | outer | Namespace that the defining class shall reside. |
[in] | class_name | Name of the class. |
[in] | super | Superclass of the defining class. |
[in] | alloc | Must be 0 for extension libraries. |
[in] | ... | Arbitrary number of const char*, terminated by NULL. Each of which are the name of fields. |
rb_eNameError | `class_name` is not a constant name. |
rb_eTypeError | `class_name` is already taken. |
rb_eArgError | Duplicated field name. |
Definition at line 460 of file struct.c.
Referenced by rb_struct_define_without_accessor_under().
Identical to rb_struct_aref(), except it takes ID instead of VALUE.
[in] | self | An instance of a struct class. |
[in] | key | Key to query. |
rb_eTypeError | `self` is not a struct. |
rb_eNameError | No such field. |
Definition at line 233 of file struct.c.
Referenced by rb_struct_getmember().
Mass-assigns a struct's fields.
[out] | self | An instance of a struct class to squash. |
[in] | values | New values. |
Definition at line 795 of file struct.c.
Referenced by rb_struct_initialize().
Queries the list of the names of the fields of the class of the given struct object.
This is almost the same as calling rb_struct_s_members() over the class of the receiver.
[in] | self | An instance of a subclass of rb_cStruct. |
Definition at line 82 of file struct.c.
Referenced by rb_struct_members().
Creates an instance of the given struct.
[in] | klass | The class of the instance to allocate. |
[in] | ... | The fields. |
Definition at line 843 of file struct.c.
Referenced by rb_struct_new().
Queries the list of the names of the fields of the given struct class.
[in] | klass | A subclass of rb_cStruct. |
Definition at line 68 of file struct.c.
Referenced by rb_struct_members(), and rb_struct_s_members().