Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature #19757] Add new API
rb_data_define
- Loading branch information
Showing
5 changed files
with
216 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include "ruby.h" | ||
|
||
static VALUE | ||
bug_data_new(VALUE self, VALUE super) | ||
{ | ||
return rb_data_define(super, "mem1", "mem2", NULL); | ||
} | ||
|
||
void | ||
Init_data(VALUE klass) | ||
{ | ||
rb_define_singleton_method(klass, "data_new", bug_data_new, 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: false | ||
require 'test/unit' | ||
require "-test-/struct" | ||
|
||
class Bug::Struct::Test_Data < Test::Unit::TestCase | ||
def test_data_new_default | ||
klass = Bug::Struct.data_new(false) | ||
assert_equal Data, klass.superclass | ||
assert_equal %i[mem1 mem2], klass.members | ||
end | ||
|
||
def test_data_new_superclass | ||
superclass = Data.define | ||
klass = Bug::Struct.data_new(superclass) | ||
assert_equal superclass, klass.superclass | ||
assert_equal %i[mem1 mem2], klass.members | ||
end | ||
end |