Skip to content

Commit a574467

Browse files
committed
[GR-19220] Made rb_respond_to work with primitives (#1869).
PullRequest: truffleruby/1230
2 parents 39f3e0b + 8005eef commit a574467

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Bug fixes:
5353
* Fixed `Kernel#clone` for `nil`, `true`, `false`, `Integer`, and `Symbol`.
5454
* Make top-level methods available in `Context#getBindings()` (#1838).
5555
* Made `Kernel#caller_locations` accept a range argument, and return `nil` when appropriate.
56+
* Made `rb_respond_to` work with primitives (#1869, @chrisseaton).
5657

5758
Compatibility:
5859

lib/truffle/truffle/cext.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,10 @@ def rb_funcall_with_block(recv, meth, args, block)
947947
recv.public_send(meth, *args, &block)
948948
end
949949

950+
def rb_respond_to(object, name)
951+
object.respond_to?(name)
952+
end
953+
950954
def rb_funcallv_public(recv, meth, args)
951955
recv.public_send(meth, *args)
952956
end

spec/ruby/optional/capi/object_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ def six(a, b, *c, &d); end
110110
@o.rb_respond_to(ObjectTest.new, :foo).should == true
111111
@o.rb_respond_to(ObjectTest.new, :bar).should == false
112112
end
113+
114+
it "can be used with primitives" do
115+
@o.rb_respond_to(true, :object_id).should == true
116+
@o.rb_respond_to(14, :succ).should == true
117+
end
113118
end
114119

115120
describe "rb_obj_respond_to" do

src/main/c/cext/ruby.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1896,7 +1896,7 @@ char* ruby_strdup(const char *str) {
18961896
// Calls
18971897

18981898
int rb_respond_to(VALUE object, ID name) {
1899-
return polyglot_as_boolean(RUBY_INVOKE_NO_WRAP(object, "respond_to?", name));
1899+
return RUBY_CEXT_INVOKE("rb_respond_to", object, ID2SYM(name));
19001900
}
19011901

19021902
VALUE rb_funcallv(VALUE object, ID name, int args_count, const VALUE *args) {

0 commit comments

Comments
 (0)