Skip to content

Commit ad65192

Browse files
authored
Add Data class implementation: Simple immutable value object
1 parent e294e6f commit ad65192

File tree

6 files changed

+716
-6
lines changed

6 files changed

+716
-6
lines changed

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ Note that each entry is kept to a minimum, see links for details.
102102

103103
Note: We're only listing outstanding class updates.
104104
105+
* Data
106+
* New core class to represent simple immutable value object. The class is
107+
similar to `Struct` and partially shares an implementation, but has more
108+
lean and strict API. [[Feature #16122]]
109+
105110
* Encoding
106111
* Encoding#replicate has been deprecated and will be removed in 3.3. [[Feature #18949]]
107112
* The dummy `Encoding::UTF_16` and `Encoding::UTF_32` encodings no longer
@@ -323,3 +328,4 @@ The following deprecated APIs are removed.
323328
[Feature #18949]: https://bugs.ruby-lang.org/issues/18949
324329
[Feature #19008]: https://bugs.ruby-lang.org/issues/19008
325330
[Feature #19026]: https://bugs.ruby-lang.org/issues/19026
331+
[Feature #16122]: https://bugs.ruby-lang.org/issues/16122

array.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5587,7 +5587,7 @@ ary_recycle_hash(VALUE hash)
55875587
* Related: Array#difference.
55885588
*/
55895589

5590-
static VALUE
5590+
VALUE
55915591
rb_ary_diff(VALUE ary1, VALUE ary2)
55925592
{
55935593
VALUE ary3;

internal/array.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ void rb_ary_cancel_sharing(VALUE ary);
3535
size_t rb_ary_size_as_embedded(VALUE ary);
3636
void rb_ary_make_embedded(VALUE ary);
3737
bool rb_ary_embeddable_p(VALUE ary);
38+
VALUE rb_ary_diff(VALUE ary1, VALUE ary2);
3839

3940
static inline VALUE rb_ary_entry_internal(VALUE ary, long offset);
4041
static inline bool ARY_PTR_USING_P(VALUE ary);

spec/ruby/core/data/constants_spec.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,22 @@
1414
end
1515
end
1616

17-
ruby_version_is '3.0' do
17+
ruby_version_is '3.0'...'3.2' do
1818
describe "Data" do
1919
it "does not exist anymore" do
2020
Object.should_not have_constant(:Data)
2121
end
2222
end
2323
end
24+
25+
ruby_version_is '3.2' do
26+
describe "Data" do
27+
it "is a new constant" do
28+
Data.superclass.should == Object
29+
end
30+
31+
it "is not deprecated" do
32+
-> { Data }.should_not complain
33+
end
34+
end
35+
end

0 commit comments

Comments
 (0)