Skip to content

Commit 69fcbdf

Browse files
committed
[Truffle] Kernel#to_s and Kernel#inspect are different.
We should use Rubinius's definition instead of our own, but there are some parts there we don't support yet and I decided to defer working on them.
1 parent 463db3d commit 69fcbdf

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

truffle/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2231,7 +2231,7 @@ public String toHexString(RubyBignum value) {
22312231

22322232
}
22332233

2234-
@CoreMethod(names = {"to_s", "inspect"})
2234+
@CoreMethod(names = "to_s")
22352235
public abstract static class ToSNode extends CoreMethodNode {
22362236

22372237
@Child private ClassNode classNode;

truffle/src/main/ruby/jruby/truffle/core/shims.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,21 @@ def rindex(obj)
184184

185185
index
186186
end
187+
end
188+
189+
module Kernel
190+
def inspect
191+
ivars = instance_variables
192+
193+
return to_s if ivars.empty?
194+
195+
prefix = "#<#{self.class}:0x#{self.object_id.to_s(16)}"
196+
197+
parts = []
198+
ivars.each do |var|
199+
parts << "#{var}=#{instance_variable_get(var).inspect}"
200+
end
201+
202+
"#{prefix} #{parts.join(', ')}>"
203+
end
187204
end

0 commit comments

Comments
 (0)