Skip to content

Define Kernel#instance_variables_to_inspect#15345

Merged
byroot merged 1 commit intoruby:masterfrom
byroot:kernel-instance_variables_to_inspect
Nov 28, 2025
Merged

Define Kernel#instance_variables_to_inspect#15345
byroot merged 1 commit intoruby:masterfrom
byroot:kernel-instance_variables_to_inspect

Conversation

@byroot
Copy link
Member

@byroot byroot commented Nov 28, 2025

[Bug #21718]

Otherwise objects that don't define it, but define a fairly liberal method_missing method will run into errors that are hard to understand:

class Foo
  def method_missing(name, ...)
    name
  end
end

p Foo.new.inspect
'Kernel#inspect': wrong argument type Symbol (expected Array) (TypeError)
	from ../test.rb:7:in '<main>'

@byroot byroot force-pushed the kernel-instance_variables_to_inspect branch from b702c99 to 22d85e6 Compare November 28, 2025 15:21
@launchable-app

This comment has been minimized.

@voxik
Copy link
Contributor

voxik commented Nov 28, 2025

Doesn't the code expect that the instance_variables_to_inspect method either not exists or return array? This proposal makes the method always exist. IOW this is IMHO not enough

[Bug #21718]

Otherwise objects that don't define it, but define a fairly liberal
`method_missing` method will run into errors that are hard to understand:

```ruby
class Foo
  def method_missing(name, ...)
    name
  end
end

p Foo.new.inspect
```

```
'Kernel#inspect': wrong argument type Symbol (expected Array) (TypeError)
	from ../test.rb:7:in '<main>'
```
@byroot byroot force-pushed the kernel-instance_variables_to_inspect branch from 22d85e6 to 4b81bd2 Compare November 28, 2025 17:04
@byroot byroot merged commit 191bfcb into ruby:master Nov 28, 2025
90 of 93 checks passed
@byroot byroot deleted the kernel-instance_variables_to_inspect branch November 28, 2025 17:35
@composerinteralia
Copy link
Contributor

composerinteralia commented Dec 1, 2025

I haven't looked too closely at this yet, but spotted one bit of awkwardness with this change:

require "delegate"
class X < Delegator
  def initialize; end
  def __getobj__; end
end
X.new.respond_to?(:instance_variables_to_inspect, true)
 warning: delegator does not forward private method #instance_variables_to_inspect

Triggered in our app by a delegator inside aws-sdk-core getting stubbed with mocha.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants