Skip to content
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ ref. https://docs.ruby-lang.org/ja/latest/function/index.html
* [x] `rb_const_defined`
* [ ] `rb_const_defined_at`
* [x] `rb_const_get`
* [ ] `rb_const_get_at`
* [x] `rb_const_get_at`
* [ ] `rb_const_list`
* [x] `rb_const_set`
* [ ] `rb_cont_call`
Expand Down
9 changes: 9 additions & 0 deletions ruby-internal-intern-variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ func RbConstGet(space VALUE, name ID) VALUE {
return VALUE(C.rb_const_get(C.VALUE(space), C.ID(name)))
}

// RbConstGetAt calls `rb_const_get_at` in C
//
// Original definition is following
//
// VALUE rb_const_get_at(VALUE space, ID name)
func RbConstGetAt(space VALUE, name ID) VALUE {
return VALUE(C.rb_const_get_at(C.VALUE(space), C.ID(name)))
}

// RbConstSet calls `rb_const_set` in C
//
// Original definition is following
Expand Down
9 changes: 9 additions & 0 deletions testdata/dummy/ext/dummy/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ void rb_dummy_tests_rb_alias(VALUE self, VALUE dst, VALUE src);
VALUE rb_dummy_tests_rb_class2name(VALUE self);
void rb_dummy_tests_rb_attr(VALUE self, VALUE name, VALUE needReader, VALUE needWriter, VALUE honourVisibility);
VALUE rb_dummy_tests_rb_const_get(VALUE self, VALUE name);
VALUE rb_dummy_tests_rb_const_get_at(VALUE self, VALUE name);
void rb_dummy_tests_rb_const_set(VALUE self, VALUE name, VALUE val);
VALUE rb_dummy_tests_rb_const_defined(VALUE self, VALUE name);
*/
Expand Down Expand Up @@ -111,6 +112,13 @@ func rb_dummy_tests_rb_const_get(klass C.VALUE, name C.VALUE) C.VALUE {
return C.VALUE(ruby.RbConstGet(ruby.VALUE(klass), constID))
}

//export rb_dummy_tests_rb_const_get_at
func rb_dummy_tests_rb_const_get_at(klass C.VALUE, name C.VALUE) C.VALUE {
constName := ruby.Value2String(ruby.VALUE(name))
constID := ruby.RbIntern(constName)
return C.VALUE(ruby.RbConstGetAt(ruby.VALUE(klass), constID))
}

//export rb_dummy_tests_rb_const_set
func rb_dummy_tests_rb_const_set(klass C.VALUE, name C.VALUE, val C.VALUE) {
constName := ruby.Value2String(ruby.VALUE(name))
Expand Down Expand Up @@ -147,6 +155,7 @@ func defineMethodsToDummyTests(rb_mDummy ruby.VALUE) {
ruby.RbDefineSingletonMethod(rb_cTests, "rb_class2name", C.rb_dummy_tests_rb_class2name, 0)
ruby.RbDefineSingletonMethod(rb_cTests, "rb_attr", C.rb_dummy_tests_rb_attr, 4)
ruby.RbDefineSingletonMethod(rb_cTests, "rb_const_get", C.rb_dummy_tests_rb_const_get, 1)
ruby.RbDefineSingletonMethod(rb_cTests, "rb_const_get_at", C.rb_dummy_tests_rb_const_get_at, 1)
ruby.RbDefineSingletonMethod(rb_cTests, "rb_const_set", C.rb_dummy_tests_rb_const_set, 2)
ruby.RbDefineSingletonMethod(rb_cTests, "rb_const_defined", C.rb_dummy_tests_rb_const_defined, 1)
}
1 change: 1 addition & 0 deletions testdata/dummy/sig/dummy/tests.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module Dummy
def self.rb_class2name: () -> string
def self.rb_attr: (string name, Integer need_reader, Integer need_writer, Integer honour_visibility) -> void
def self.rb_const_get: (string name) -> untyped
def self.rb_const_get_at: (string name) -> untyped
def self.rb_const_set: (string name, untyped val) -> void
def self.rb_const_defined: (string name) -> bool
end
Expand Down
6 changes: 6 additions & 0 deletions testdata/dummy/spec/dummy/tests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@
end
end

describe ".rb_const_get_at" do
it "works" do
expect(Dummy::Tests.rb_const_get_at("CONST")).to eq "TEST"
end
end

describe ".rb_const_set" do
after do
silence_warning do
Expand Down