Skip to content

Add object_id to protected methods - #92

Open
FionaDL wants to merge 1 commit into
ruby:masterfrom
FionaDL:object-id-warning
Open

Add object_id to protected methods#92
FionaDL wants to merge 1 commit into
ruby:masterfrom
FionaDL:object-id-warning

Conversation

@FionaDL

@FionaDL FionaDL commented Dec 15, 2025

Copy link
Copy Markdown

This PR fixes issue #75.

While working on a project with ruby 3.4.7 we were continuously seeing the following warning:

warning: redefining 'object_id' may cause serious problems

This PR adds object_id to the check for protected methods.

@gemmaro gemmaro left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding test cases for this change might be useful, since there are assertions for protected methods, such as bang methods (e.g. in test_override_subclass).

Comment thread lib/ostruct.rb
private def is_method_protected!(name) # :nodoc:
if !respond_to?(name, true)
false
elsif name.match?(/^object_id$/)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String comparison should be less expensive than Regexp:

Suggested change
elsif name.match?(/^object_id$/)
elsif 'object_id' == name

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