1 /**********************************************************************
6 created at: Tue Mar 22 18:44:30 JST 1995
8 Copyright (C) 1993-2007 Yukihiro Matsumoto
10 **********************************************************************/
12 #include "ruby/ruby.h"
16 static VALUE
struct_alloc(VALUE
);
19 rb_struct_iv_get(VALUE c
, const char *name
)
25 if (rb_ivar_defined(c
, id
))
26 return rb_ivar_get(c
, id
);
28 if (c
== 0 || c
== rb_cStruct
)
34 rb_struct_s_members(VALUE klass
)
36 VALUE members
= rb_struct_iv_get(klass
, "__members__");
39 rb_raise(rb_eTypeError
, "uninitialized struct");
41 if (TYPE(members
) != T_ARRAY
) {
42 rb_raise(rb_eTypeError
, "corrupted struct");
48 rb_struct_members(VALUE s
)
50 VALUE members
= rb_struct_s_members(rb_obj_class(s
));
52 if (RSTRUCT_LEN(s
) != RARRAY_LEN(members
)) {
53 rb_raise(rb_eTypeError
, "struct size differs (%ld required %ld given)",
54 RARRAY_LEN(members
), RSTRUCT_LEN(s
));
60 rb_struct_s_members_m(VALUE klass
)
65 members
= rb_struct_s_members(klass
);
66 ary
= rb_ary_new2(RARRAY_LEN(members
));
67 p
= RARRAY_PTR(members
); pend
= p
+ RARRAY_LEN(members
);
78 * struct.members => array
80 * Returns an array of strings representing the names of the instance
83 * Customer = Struct.new(:name, :address, :zip)
84 * joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
85 * joe.members #=> [:name, :address, :zip]
89 rb_struct_members_m(VALUE obj
)
91 return rb_struct_s_members_m(rb_obj_class(obj
));
95 rb_struct_getmember(VALUE obj
, ID id
)
100 members
= rb_struct_members(obj
);
102 for (i
=0; i
<RARRAY_LEN(members
); i
++) {
103 if (RARRAY_PTR(members
)[i
] == slot
) {
104 return RSTRUCT_PTR(obj
)[i
];
107 rb_name_error(id
, "%s is not struct member", rb_id2name(id
));
108 return Qnil
; /* not reached */
112 rb_struct_ref(VALUE obj
)
114 return rb_struct_getmember(obj
, rb_frame_this_func());
117 static VALUE
rb_struct_ref0(VALUE obj
) {return RSTRUCT_PTR(obj
)[0];}
118 static VALUE
rb_struct_ref1(VALUE obj
) {return RSTRUCT_PTR(obj
)[1];}
119 static VALUE
rb_struct_ref2(VALUE obj
) {return RSTRUCT_PTR(obj
)[2];}
120 static VALUE
rb_struct_ref3(VALUE obj
) {return RSTRUCT_PTR(obj
)[3];}
121 static VALUE
rb_struct_ref4(VALUE obj
) {return RSTRUCT_PTR(obj
)[4];}
122 static VALUE
rb_struct_ref5(VALUE obj
) {return RSTRUCT_PTR(obj
)[5];}
123 static VALUE
rb_struct_ref6(VALUE obj
) {return RSTRUCT_PTR(obj
)[6];}
124 static VALUE
rb_struct_ref7(VALUE obj
) {return RSTRUCT_PTR(obj
)[7];}
125 static VALUE
rb_struct_ref8(VALUE obj
) {return RSTRUCT_PTR(obj
)[8];}
126 static VALUE
rb_struct_ref9(VALUE obj
) {return RSTRUCT_PTR(obj
)[9];}
128 #define N_REF_FUNC (sizeof(ref_func) / sizeof(ref_func[0]))
130 static VALUE (*const ref_func
[])(VALUE
) = {
144 rb_struct_modify(VALUE s
)
146 if (OBJ_FROZEN(s
)) rb_error_frozen("Struct");
147 if (!OBJ_TAINTED(s
) && rb_safe_level() >= 4)
148 rb_raise(rb_eSecurityError
, "Insecure: can't modify Struct");
152 rb_struct_set(VALUE obj
, VALUE val
)
157 members
= rb_struct_members(obj
);
158 rb_struct_modify(obj
);
159 for (i
=0; i
<RARRAY_LEN(members
); i
++) {
160 slot
= RARRAY_PTR(members
)[i
];
161 if (rb_id_attrset(SYM2ID(slot
)) == rb_frame_this_func()) {
162 return RSTRUCT_PTR(obj
)[i
] = val
;
165 rb_name_error(rb_frame_this_func(), "`%s' is not a struct member",
166 rb_id2name(rb_frame_this_func()));
167 return Qnil
; /* not reached */
171 make_struct(VALUE name
, VALUE members
, VALUE klass
)
179 nstr
= rb_class_new(klass
);
180 rb_make_metaclass(nstr
, RBASIC(klass
)->klass
);
181 rb_class_inherited(klass
, nstr
);
184 id
= SYM2ID(rb_str_intern(name
));
185 if (!rb_is_const_id(id
)) {
186 rb_name_error(id
, "identifier %s needs to be constant", StringValuePtr(name
));
188 if (rb_const_defined_at(klass
, id
)) {
189 rb_warn("redefining constant Struct::%s", StringValuePtr(name
));
190 rb_mod_remove_const(klass
, ID2SYM(id
));
192 nstr
= rb_define_class_under(klass
, rb_id2name(id
), klass
);
194 rb_iv_set(nstr
, "__size__", LONG2NUM(RARRAY_LEN(members
)));
195 rb_iv_set(nstr
, "__members__", members
);
197 rb_define_alloc_func(nstr
, struct_alloc
);
198 rb_define_singleton_method(nstr
, "new", rb_class_new_instance
, -1);
199 rb_define_singleton_method(nstr
, "[]", rb_class_new_instance
, -1);
200 rb_define_singleton_method(nstr
, "members", rb_struct_s_members_m
, 0);
201 for (i
=0; i
< RARRAY_LEN(members
); i
++) {
202 ID id
= SYM2ID(RARRAY_PTR(members
)[i
]);
203 if (rb_is_local_id(id
) || rb_is_const_id(id
)) {
204 if (i
< N_REF_FUNC
) {
205 rb_define_method_id(nstr
, id
, ref_func
[i
], 0);
208 rb_define_method_id(nstr
, id
, rb_struct_ref
, 0);
210 rb_define_method_id(nstr
, rb_id_attrset(id
), rb_struct_set
, 1);
218 rb_struct_alloc_noinit(VALUE klass
)
220 return struct_alloc(klass
);
224 rb_struct_define_without_accessor(char *class_name
, VALUE super
, rb_alloc_func_t alloc
, ...)
232 members
= rb_ary_new2(0);
235 while ((name
= va_arg(ar
, char*)) != NULL
) {
236 rb_ary_push(members
, ID2SYM(rb_intern(name
)));
242 klass
= rb_define_class(class_name
, super
);
245 klass
= rb_class_new(super
);
246 rb_make_metaclass(klass
, RBASIC(super
)->klass
);
247 rb_class_inherited(super
, klass
);
250 rb_iv_set(klass
, "__size__", LONG2NUM(RARRAY_LEN(members
)));
251 rb_iv_set(klass
, "__members__", members
);
254 rb_define_alloc_func(klass
, alloc
);
256 rb_define_alloc_func(klass
, struct_alloc
);
262 rb_struct_define(const char *name
, ...)
268 if (!name
) nm
= Qnil
;
269 else nm
= rb_str_new2(name
);
273 while ((mem
= va_arg(ar
, char*)) != 0) {
274 ID slot
= rb_intern(mem
);
275 rb_ary_push(ary
, ID2SYM(slot
));
279 return make_struct(nm
, ary
, rb_cStruct
);
284 * Struct.new( [aString] [, aSym]+> ) => StructClass
285 * StructClass.new(arg, ...) => obj
286 * StructClass[arg, ...] => obj
288 * Creates a new class, named by <i>aString</i>, containing accessor
289 * methods for the given symbols. If the name <i>aString</i> is
290 * omitted, an anonymous structure class will be created. Otherwise,
291 * the name of this struct will appear as a constant in class
292 * <code>Struct</code>, so it must be unique for all
293 * <code>Struct</code>s in the system and should start with a capital
294 * letter. Assigning a structure class to a constant effectively gives
295 * the class the name of the constant.
297 * <code>Struct::new</code> returns a new <code>Class</code> object,
298 * which can then be used to create specific instances of the new
299 * structure. The number of actual parameters must be
300 * less than or equal to the number of attributes defined for this
301 * class; unset parameters default to \nil{}. Passing too many
302 * parameters will raise an \E{ArgumentError}.
304 * The remaining methods listed in this section (class and instance)
305 * are defined for this generated class.
307 * # Create a structure with a name in Struct
308 * Struct.new("Customer", :name, :address) #=> Struct::Customer
309 * Struct::Customer.new("Dave", "123 Main") #=> #<struct Struct::Customer name="Dave", address="123 Main">
311 * # Create a structure named by its constant
312 * Customer = Struct.new(:name, :address) #=> Customer
313 * Customer.new("Dave", "123 Main") #=> #<struct Customer name="Dave", address="123 Main">
317 rb_struct_s_def(int argc
, VALUE
*argv
, VALUE klass
)
324 rb_scan_args(argc
, argv
, "1*", &name
, &rest
);
325 for (i
=0; i
<RARRAY_LEN(rest
); i
++) {
326 id
= rb_to_id(RARRAY_PTR(rest
)[i
]);
327 RARRAY_PTR(rest
)[i
] = ID2SYM(id
);
329 if (!NIL_P(name
) && SYMBOL_P(name
)) {
330 rb_ary_unshift(rest
, name
);
333 st
= make_struct(name
, rest
, klass
);
334 if (rb_block_given_p()) {
335 rb_mod_module_eval(0, 0, st
);
345 rb_struct_initialize(VALUE self
, VALUE values
)
347 VALUE klass
= rb_obj_class(self
);
351 rb_struct_modify(self
);
352 size
= rb_struct_iv_get(klass
, "__size__");
354 if (n
< RARRAY_LEN(values
)) {
355 rb_raise(rb_eArgError
, "struct size differs");
357 MEMCPY(RSTRUCT_PTR(self
), RARRAY_PTR(values
), VALUE
, RARRAY_LEN(values
));
358 if (n
> RARRAY_LEN(values
)) {
359 rb_mem_clear(RSTRUCT_PTR(self
)+RARRAY_LEN(values
),
360 n
-RARRAY_LEN(values
));
366 struct_alloc(VALUE klass
)
370 NEWOBJ(st
, struct RStruct
);
371 OBJSETUP(st
, klass
, T_STRUCT
);
373 size
= rb_struct_iv_get(klass
, "__size__");
376 if (0 < n
&& n
<= RSTRUCT_EMBED_LEN_MAX
) {
377 RBASIC(st
)->flags
&= ~RSTRUCT_EMBED_LEN_MASK
;
378 RBASIC(st
)->flags
|= n
<< RSTRUCT_EMBED_LEN_SHIFT
;
379 rb_mem_clear(st
->as
.ary
, n
);
382 st
->as
.heap
.ptr
= ALLOC_N(VALUE
, n
);
383 rb_mem_clear(st
->as
.heap
.ptr
, n
);
391 rb_struct_alloc(VALUE klass
, VALUE values
)
393 return rb_class_new_instance(RARRAY_LEN(values
), RARRAY_PTR(values
), klass
);
397 rb_struct_new(VALUE klass
, ...)
403 sz
= rb_struct_iv_get(klass
, "__size__");
405 mem
= ALLOCA_N(VALUE
, size
);
406 va_start(args
, klass
);
407 for (i
=0; i
<size
; i
++) {
408 mem
[i
] = va_arg(args
, VALUE
);
412 return rb_class_new_instance(size
, mem
, klass
);
417 * struct.each {|obj| block } => struct
419 * Calls <i>block</i> once for each instance variable, passing the
420 * value as a parameter.
422 * Customer = Struct.new(:name, :address, :zip)
423 * joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
424 * joe.each {|x| puts(x) }
429 * 123 Maple, Anytown NC
434 rb_struct_each(VALUE s
)
438 RETURN_ENUMERATOR(s
, 0, 0);
439 for (i
=0; i
<RSTRUCT_LEN(s
); i
++) {
440 rb_yield(RSTRUCT_PTR(s
)[i
]);
447 * struct.each_pair {|sym, obj| block } => struct
449 * Calls <i>block</i> once for each instance variable, passing the name
450 * (as a symbol) and the value as parameters.
452 * Customer = Struct.new(:name, :address, :zip)
453 * joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
454 * joe.each_pair {|name, value| puts("#{name} => #{value}") }
459 * address => 123 Maple, Anytown NC
464 rb_struct_each_pair(VALUE s
)
469 RETURN_ENUMERATOR(s
, 0, 0);
470 members
= rb_struct_members(s
);
471 for (i
=0; i
<RSTRUCT_LEN(s
); i
++) {
472 rb_yield_values(2, rb_ary_entry(members
, i
), RSTRUCT_PTR(s
)[i
]);
478 inspect_struct(VALUE s
, VALUE dummy
, int recur
)
480 char *cname
= rb_class2name(rb_obj_class(s
));
485 return rb_sprintf("#<struct %s:...>", cname
);
488 members
= rb_struct_members(s
);
489 if (cname
[0] == '#') {
490 str
= rb_str_new2("#<struct ");
493 str
= rb_sprintf("#<struct %s ", cname
);
495 for (i
=0; i
<RSTRUCT_LEN(s
); i
++) {
500 rb_str_cat2(str
, ", ");
502 slot
= RARRAY_PTR(members
)[i
];
504 if (rb_is_local_id(id
) || rb_is_const_id(id
)) {
505 rb_str_append(str
, rb_id2str(id
));
508 rb_str_append(str
, rb_inspect(slot
));
510 rb_str_cat2(str
, "=");
511 rb_str_append(str
, rb_inspect(RSTRUCT_PTR(s
)[i
]));
513 rb_str_cat2(str
, ">");
521 * struct.to_s => string
522 * struct.inspect => string
524 * Describe the contents of this struct in a string.
528 rb_struct_inspect(VALUE s
)
530 return rb_exec_recursive(inspect_struct
, s
, 0);
535 * struct.to_a => array
536 * struct.values => array
538 * Returns the values for this instance as an array.
540 * Customer = Struct.new(:name, :address, :zip)
541 * joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
542 * joe.to_a[1] #=> "123 Maple, Anytown NC"
546 rb_struct_to_a(VALUE s
)
548 return rb_ary_new4(RSTRUCT_LEN(s
), RSTRUCT_PTR(s
));
553 rb_struct_init_copy(VALUE copy
, VALUE s
)
555 if (copy
== s
) return copy
;
556 rb_check_frozen(copy
);
557 if (!rb_obj_is_instance_of(s
, rb_obj_class(copy
))) {
558 rb_raise(rb_eTypeError
, "wrong argument class");
560 if (RSTRUCT_LEN(copy
) != RSTRUCT_LEN(s
)) {
561 rb_raise(rb_eTypeError
, "struct size mismatch");
563 MEMCPY(RSTRUCT_PTR(copy
), RSTRUCT_PTR(s
), VALUE
, RSTRUCT_LEN(copy
));
569 rb_struct_aref_id(VALUE s
, ID id
)
574 members
= rb_struct_members(s
);
575 len
= RARRAY_LEN(members
);
576 for (i
=0; i
<len
; i
++) {
577 if (SYM2ID(RARRAY_PTR(members
)[i
]) == id
) {
578 return RSTRUCT_PTR(s
)[i
];
581 rb_name_error(id
, "no member '%s' in struct", rb_id2name(id
));
582 return Qnil
; /* not reached */
587 * struct[symbol] => anObject
588 * struct[fixnum] => anObject
590 * Attribute Reference---Returns the value of the instance variable
591 * named by <i>symbol</i>, or indexed (0..length-1) by
592 * <i>fixnum</i>. Will raise <code>NameError</code> if the named
593 * variable does not exist, or <code>IndexError</code> if the index is
596 * Customer = Struct.new(:name, :address, :zip)
597 * joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
599 * joe["name"] #=> "Joe Smith"
600 * joe[:name] #=> "Joe Smith"
601 * joe[0] #=> "Joe Smith"
605 rb_struct_aref(VALUE s
, VALUE idx
)
609 if (TYPE(idx
) == T_STRING
|| TYPE(idx
) == T_SYMBOL
) {
610 return rb_struct_aref_id(s
, rb_to_id(idx
));
614 if (i
< 0) i
= RSTRUCT_LEN(s
) + i
;
616 rb_raise(rb_eIndexError
, "offset %ld too small for struct(size:%ld)",
618 if (RSTRUCT_LEN(s
) <= i
)
619 rb_raise(rb_eIndexError
, "offset %ld too large for struct(size:%ld)",
621 return RSTRUCT_PTR(s
)[i
];
625 rb_struct_aset_id(VALUE s
, ID id
, VALUE val
)
630 members
= rb_struct_members(s
);
632 len
= RARRAY_LEN(members
);
633 if (RSTRUCT_LEN(s
) != RARRAY_LEN(members
)) {
634 rb_raise(rb_eTypeError
, "struct size differs (%ld required %ld given)",
635 RARRAY_LEN(members
), RSTRUCT_LEN(s
));
637 for (i
=0; i
<len
; i
++) {
638 if (SYM2ID(RARRAY_PTR(members
)[i
]) == id
) {
639 RSTRUCT_PTR(s
)[i
] = val
;
643 rb_name_error(id
, "no member '%s' in struct", rb_id2name(id
));
648 * struct[symbol] = obj => obj
649 * struct[fixnum] = obj => obj
651 * Attribute Assignment---Assigns to the instance variable named by
652 * <i>symbol</i> or <i>fixnum</i> the value <i>obj</i> and
653 * returns it. Will raise a <code>NameError</code> if the named
654 * variable does not exist, or an <code>IndexError</code> if the index
657 * Customer = Struct.new(:name, :address, :zip)
658 * joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
660 * joe["name"] = "Luke"
661 * joe[:zip] = "90210"
663 * joe.name #=> "Luke"
664 * joe.zip #=> "90210"
668 rb_struct_aset(VALUE s
, VALUE idx
, VALUE val
)
672 if (TYPE(idx
) == T_STRING
|| TYPE(idx
) == T_SYMBOL
) {
673 return rb_struct_aset_id(s
, rb_to_id(idx
), val
);
677 if (i
< 0) i
= RSTRUCT_LEN(s
) + i
;
679 rb_raise(rb_eIndexError
, "offset %ld too small for struct(size:%ld)",
682 if (RSTRUCT_LEN(s
) <= i
) {
683 rb_raise(rb_eIndexError
, "offset %ld too large for struct(size:%ld)",
687 return RSTRUCT_PTR(s
)[i
] = val
;
691 struct_entry(VALUE s
, long n
)
693 return rb_struct_aref(s
, LONG2NUM(n
));
698 * struct.values_at(selector,... ) => an_array
700 * Returns an array containing the elements in
701 * _self_ corresponding to the given selector(s). The selectors
702 * may be either integer indices or ranges.
703 * See also </code>.select<code>.
705 * a = %w{ a b c d e f }
706 * a.values_at(1, 3, 5)
707 * a.values_at(1, 3, 5, 7)
708 * a.values_at(-1, -3, -5, -7)
709 * a.values_at(1..3, 2...5)
713 rb_struct_values_at(int argc
, VALUE
*argv
, VALUE s
)
715 return rb_get_values_at(s
, RSTRUCT_LEN(s
), argc
, argv
, struct_entry
);
720 * struct.select {|i| block } => array
722 * Invokes the block passing in successive elements from
723 * <i>struct</i>, returning an array containing those elements
724 * for which the block returns a true value (equivalent to
725 * <code>Enumerable#select</code>).
727 * Lots = Struct.new(:a, :b, :c, :d, :e, :f)
728 * l = Lots.new(11, 22, 33, 44, 55, 66)
729 * l.select {|v| (v % 2).zero? } #=> [22, 44, 66]
733 rb_struct_select(int argc
, VALUE
*argv
, VALUE s
)
739 rb_raise(rb_eArgError
, "wrong number of arguments (%d for 0)", argc
);
741 result
= rb_ary_new();
742 for (i
= 0; i
< RSTRUCT_LEN(s
); i
++) {
743 if (RTEST(rb_yield(RSTRUCT_PTR(s
)[i
]))) {
744 rb_ary_push(result
, RSTRUCT_PTR(s
)[i
]);
753 * struct == other_struct => true or false
755 * Equality---Returns <code>true</code> if <i>other_struct</i> is
756 * equal to this one: they must be of the same class as generated by
757 * <code>Struct::new</code>, and the values of all instance variables
758 * must be equal (according to <code>Object#==</code>).
760 * Customer = Struct.new(:name, :address, :zip)
761 * joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
762 * joejr = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
763 * jane = Customer.new("Jane Doe", "456 Elm, Anytown NC", 12345)
764 * joe == joejr #=> true
765 * joe == jane #=> false
769 rb_struct_equal(VALUE s
, VALUE s2
)
773 if (s
== s2
) return Qtrue
;
774 if (TYPE(s2
) != T_STRUCT
) return Qfalse
;
775 if (rb_obj_class(s
) != rb_obj_class(s2
)) return Qfalse
;
776 if (RSTRUCT_LEN(s
) != RSTRUCT_LEN(s2
)) {
777 rb_bug("inconsistent struct"); /* should never happen */
780 for (i
=0; i
<RSTRUCT_LEN(s
); i
++) {
781 if (!rb_equal(RSTRUCT_PTR(s
)[i
], RSTRUCT_PTR(s2
)[i
])) return Qfalse
;
788 * struct.hash => fixnum
790 * Return a hash value based on this struct's contents.
794 rb_struct_hash(VALUE s
)
799 h
= rb_hash(rb_obj_class(s
));
800 for (i
= 0; i
< RSTRUCT_LEN(s
); i
++) {
801 h
= (h
<< 1) | (h
<0 ? 1 : 0);
802 n
= rb_hash(RSTRUCT_PTR(s
)[i
]);
810 * struct.eql?(other) => true or false
812 * Two structures are equal if they are the same object, or if all their
813 * fields are equal (using <code>eql?</code>).
817 rb_struct_eql(VALUE s
, VALUE s2
)
821 if (s
== s2
) return Qtrue
;
822 if (TYPE(s2
) != T_STRUCT
) return Qfalse
;
823 if (rb_obj_class(s
) != rb_obj_class(s2
)) return Qfalse
;
824 if (RSTRUCT_LEN(s
) != RSTRUCT_LEN(s2
)) {
825 rb_bug("inconsistent struct"); /* should never happen */
828 for (i
=0; i
<RSTRUCT_LEN(s
); i
++) {
829 if (!rb_eql(RSTRUCT_PTR(s
)[i
], RSTRUCT_PTR(s2
)[i
])) return Qfalse
;
836 * struct.length => fixnum
837 * struct.size => fixnum
839 * Returns the number of instance variables.
841 * Customer = Struct.new(:name, :address, :zip)
842 * joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
847 rb_struct_size(VALUE s
)
849 return LONG2FIX(RSTRUCT_LEN(s
));
853 * A <code>Struct</code> is a convenient way to bundle a number of
854 * attributes together, using accessor methods, without having to write
857 * The <code>Struct</code> class is a generator of specific classes,
858 * each one of which is defined to hold a set of variables and their
859 * accessors. In these examples, we'll call the generated class
860 * ``<i>Customer</i>Class,'' and we'll show an example instance of that
861 * class as ``<i>Customer</i>Inst.''
863 * In the descriptions that follow, the parameter <i>symbol</i> refers
864 * to a symbol, which is either a quoted string or a
865 * <code>Symbol</code> (such as <code>:name</code>).
870 rb_cStruct
= rb_define_class("Struct", rb_cObject
);
871 rb_include_module(rb_cStruct
, rb_mEnumerable
);
873 rb_undef_alloc_func(rb_cStruct
);
874 rb_define_singleton_method(rb_cStruct
, "new", rb_struct_s_def
, -1);
876 rb_define_method(rb_cStruct
, "initialize", rb_struct_initialize
, -2);
877 rb_define_method(rb_cStruct
, "initialize_copy", rb_struct_init_copy
, 1);
879 rb_define_method(rb_cStruct
, "==", rb_struct_equal
, 1);
880 rb_define_method(rb_cStruct
, "eql?", rb_struct_eql
, 1);
881 rb_define_method(rb_cStruct
, "hash", rb_struct_hash
, 0);
883 rb_define_method(rb_cStruct
, "to_s", rb_struct_inspect
, 0);
884 rb_define_method(rb_cStruct
, "inspect", rb_struct_inspect
, 0);
885 rb_define_method(rb_cStruct
, "to_a", rb_struct_to_a
, 0);
886 rb_define_method(rb_cStruct
, "values", rb_struct_to_a
, 0);
887 rb_define_method(rb_cStruct
, "size", rb_struct_size
, 0);
888 rb_define_method(rb_cStruct
, "length", rb_struct_size
, 0);
890 rb_define_method(rb_cStruct
, "each", rb_struct_each
, 0);
891 rb_define_method(rb_cStruct
, "each_pair", rb_struct_each_pair
, 0);
892 rb_define_method(rb_cStruct
, "[]", rb_struct_aref
, 1);
893 rb_define_method(rb_cStruct
, "[]=", rb_struct_aset
, 2);
894 rb_define_method(rb_cStruct
, "select", rb_struct_select
, -1);
895 rb_define_method(rb_cStruct
, "values_at", rb_struct_values_at
, -1);
897 rb_define_method(rb_cStruct
, "members", rb_struct_members_m
, 0);