Feature #19261 » data-members-remove-method.patch
struct.c | ||
---|---|---|
#define rb_data_s_members_m rb_struct_s_members_m
|
||
/*
|
||
* call-seq:
|
||
* new(*args) -> instance
|
||
... | ... | |
#define rb_data_to_h rb_struct_to_h
|
||
/*
|
||
* call-seq:
|
||
* members -> array_of_symbols
|
||
*
|
||
* Returns the member names from +self+ as an array:
|
||
*
|
||
* Measure = Data.define(:amount, :unit)
|
||
* distance = Measure[10, 'km']
|
||
*
|
||
* distance.members #=> [:amount, :unit]
|
||
*
|
||
*/
|
||
#define rb_data_members_m rb_struct_members_m
|
||
/*
|
||
* call-seq:
|
||
* deconstruct -> array
|
||
... | ... | |
rb_define_method(rb_cData, "inspect", rb_data_inspect, 0);
|
||
rb_define_alias(rb_cData, "to_s", "inspect");
|
||
rb_define_method(rb_cData, "to_h", rb_data_to_h, 0);
|
||
rb_define_method(rb_cData, "members", rb_data_members_m, 0);
|
||
rb_define_method(rb_cData, "to_h", rb_data_to_h, 0);
|
||
rb_define_method(rb_cData, "deconstruct", rb_data_deconstruct, 0);
|
||
rb_define_method(rb_cData, "deconstruct_keys", rb_data_deconstruct_keys, 1);
|
test/ruby/test_data.rb | ||
---|---|---|
test = klass.new(1, 2)
|
||
assert_equal(1, test.foo)
|
||
assert_equal(2, test.bar)
|
||
assert_equal(%i[foo bar], test.members)
|
||
assert_equal(1, test.public_send(:foo))
|
||
assert_equal(0, test.method(:foo).arity)
|
||
assert_equal([], test.method(:foo).parameters)
|
||
... | ... | |
assert_not_equal(Data.define.new, test)
|
||
assert_equal('#<data >', test.inspect)
|
||
assert_equal([], test.members)
|
||
assert_equal({}, test.to_h)
|
||
end
|
||