Skip to content

Commit 6501dc5

Browse files
committed
Remove the inconsistent special case for foreign_object.respond_to?(:class)
1 parent 5ed94f9 commit 6501dc5

File tree

5 files changed

+1
-27
lines changed

5 files changed

+1
-27
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Changes:
4848
* `foreign_object.class` on foreign objects is no longer special and uses `Kernel#class` (it used to return the `java.lang.Class` object for a Java type or `getMetaObject()`, but that is too incompatible with Ruby code).
4949
* `Java.import name` imports a Java class in the enclosing module instead of always as a top-level constant.
5050
* `foreign_object.keys` no longer returns members, use `foreign_object.instance_variables` or `foreign_object.methods` instead.
51+
* `foreign_object.respond_to?(:class)` is now always true (before it was only for Java classes), since the method is always defined.
5152

5253
# 21.2.0
5354

doc/contributor/interop.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ runtime object instance.
113113

114114
`foreign_object.kind_of?` works like `foreign_object.is_a?`.
115115

116-
`object.respond_to?(:class)` calls `Truffle::Interop.java_class?(object)`.
117-
118116
`object.respond_to?(name)` for other names returns `false`.
119117

120118
`object.__send__(name, *args)` works in the same way as literal method call on

doc/user/polyglot.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ If you want to pass a Ruby object to another language for fields to be read and
110110

111111
`object.respond_to?(:new)` will tell you if a foreign object can be used to create a new object (if it's a class).
112112

113-
`object.respond_to?(:class)` will tell you if an object is a Java class.
114-
115113
`Polyglot.as_enumerable(object)` will create a Ruby `Enumerable` from the foreign object, using its size or length, and reading from it.
116114

117115
Where boolean value is expected (e.g., in `if` conditions) the foreign value is converted to boolean if possible or considered to be true.

spec/truffle/interop/respond_to_spec.rb

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,4 @@
6262
Truffle::Interop.java_array(1, 2, 3).should.respond_to?(:is_a?)
6363
end
6464
end
65-
66-
describe "for :class" do
67-
it "and a Java class returns true" do
68-
Truffle::Debug.java_class.should.respond_to?(:class)
69-
end
70-
71-
it "and a Java object returns false" do
72-
Truffle::Debug.java_object.should_not.respond_to?(:class)
73-
end
74-
75-
it "and a Java array returns false" do
76-
Truffle::Interop.java_array(1, 2, 3).should_not.respond_to?(:class)
77-
end
78-
end
7965
end

src/main/ruby/truffleruby/core/truffle/polyglot.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -342,15 +342,6 @@ def inspect
342342
end
343343

344344
class ForeignObject < Object
345-
def respond_to?(name, include_all = false)
346-
case symbol = name.to_sym
347-
when :class
348-
Truffle::Interop.java_class?(self)
349-
else
350-
super(symbol, include_all)
351-
end
352-
end
353-
354345
def inspect
355346
recursive_string_for(self) if Truffle::ThreadOperations.detect_recursion self do
356347
return Truffle::InteropOperations.foreign_inspect_nonrecursive(self)

0 commit comments

Comments
 (0)