Skip to content

Add Data class implementation: Simple immutable value object #6353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ Note that each entry is kept to a minimum, see links for details.

Note: We're only listing outstanding class updates.

* Data
* New core class to represent simple immutable value object. The class is
similar to `Struct` and partially shares an implementation, but has more
lean and strict API. [[Feature #16122]]

* Encoding
* Encoding#replicate has been deprecated and will be removed in 3.3. [[Feature #18949]]
* The dummy `Encoding::UTF_16` and `Encoding::UTF_32` encodings no longer
Expand Down Expand Up @@ -323,3 +328,4 @@ The following deprecated APIs are removed.
[Feature #18949]: https://bugs.ruby-lang.org/issues/18949
[Feature #19008]: https://bugs.ruby-lang.org/issues/19008
[Feature #19026]: https://bugs.ruby-lang.org/issues/19026
[Feature #16122]: https://bugs.ruby-lang.org/issues/16122
2 changes: 1 addition & 1 deletion array.c
Original file line number Diff line number Diff line change
Expand Up @@ -5587,7 +5587,7 @@ ary_recycle_hash(VALUE hash)
* Related: Array#difference.
*/

static VALUE
VALUE
rb_ary_diff(VALUE ary1, VALUE ary2)
{
VALUE ary3;
Expand Down
1 change: 1 addition & 0 deletions internal/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ void rb_ary_cancel_sharing(VALUE ary);
size_t rb_ary_size_as_embedded(VALUE ary);
void rb_ary_make_embedded(VALUE ary);
bool rb_ary_embeddable_p(VALUE ary);
VALUE rb_ary_diff(VALUE ary1, VALUE ary2);

static inline VALUE rb_ary_entry_internal(VALUE ary, long offset);
static inline bool ARY_PTR_USING_P(VALUE ary);
Expand Down
14 changes: 13 additions & 1 deletion spec/ruby/core/data/constants_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,22 @@
end
end

ruby_version_is '3.0' do
ruby_version_is '3.0'...'3.2' do
describe "Data" do
it "does not exist anymore" do
Object.should_not have_constant(:Data)
end
end
end

ruby_version_is '3.2' do
describe "Data" do
it "is a new constant" do
Data.superclass.should == Object
end

it "is not deprecated" do
-> { Data }.should_not complain
end
end
end
Loading