Skip to content

Exclude custom instance variables from State#to_h - #1094

Merged
byroot merged 1 commit into
ruby:masterfrom
ydah:fix-state-to-h-ivars
Oct 5, 2026
Merged

byroot merged 1 commit into
ruby:masterfrom
ydah:fix-state-to-h-ivars

Conversation

@ydah

@ydah ydah commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

Remove the leftover support for arbitrary instance variables in State#to_h after State#[] was removed in 3.0.0.

require "json"

state = JSON::State.new
state.instance_variable_set(:@custom, 42)
state.to_h.key?(:custom)
# Before (CRuby): NoMethodError
# After: false

Return only known configuration options on CRuby, JRuby, and TruffleRuby. Add regression coverage for both to_h and to_hash.

@byroot

byroot commented Oct 5, 2026

Copy link
Copy Markdown
Member

That's something I removed in 3.0. It's true I forgot some dead code though, but I'd rather remove the leftovers than to re-introduce this mis-feature.

@ydah ydah changed the title Fix State#to_h for states with instance variables Exclude custom instance variables from State#to_h Oct 5, 2026
@ydah
ydah force-pushed the fix-state-to-h-ivars branch from 3b9ee20 to 2cacb86 Compare October 5, 2026 14:04
@ydah

ydah commented Oct 5, 2026

Copy link
Copy Markdown
Member Author

Thanks for clarifying. I've removed the leftover instance variable handling and aligned TruffleRuby so that to_h only returns known configuration options. What do you think?

@byroot
byroot merged commit 08e7229 into ruby:master Oct 5, 2026
42 checks passed
@byroot

byroot commented Oct 5, 2026

Copy link
Copy Markdown
Member

Thank you!

@ydah
ydah deleted the fix-state-to-h-ivars branch October 5, 2026 22:10
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.

2 participants