Skip to content

Conversation

@djberube
Copy link

Adds has_key? method to OpenStruct class to check if a given name exists as a member, which allows checking for presence of a key without creating an accessor method; it also allows for distinguishing between a method which has never been set and one which been set to nil.

@marcandre
Copy link
Member

What is the usecase?

@ingemar
Copy link

ingemar commented May 30, 2025

@djberube I would argue that this method should be named #include? as in Hash#include?, and subsequently aliased as #has_key? and #key?. What do you think?

@o-200
Copy link

o-200 commented Sep 21, 2025

Hey, for me it's will helpful when i need to validate the structure and serialize JSON and API'S.

I am really interested of that and i want to finish implementing the feature of seeking keys in OpenStruct. Can i just create my own fork and give Co-Authoring to @djberube when it will be done?

Durable Programming, LLC and others added 2 commits September 21, 2025 09:38
Adds has_key? method to OpenStruct class to check if a given name exists as a member. This allows checking for presence of a key without creating an accessor method. Method accepts both string and symbol keys, converting them to symbols before checking. Includes comprehensive test coverage for various usage scenarios.
@djberube
Copy link
Author

djberube commented Sep 21, 2025

@djberube I would argue that this method should be named #include? as in Hash#include?, and subsequently aliased as #has_key? and #key?. What do you think?

Makes sense; we should follow what Hash does.

Adjusted as requested.

@o-200 I have made the requested changes, but feel free to suggest any changes that would help your use case.

@o-200
Copy link

o-200 commented Sep 21, 2025

@o-200 I have made the requested changes,

Thanks! Appreciate that you returned after six months to finish that pull request.

@ingemar
Copy link

ingemar commented Sep 22, 2025

@djberube This is excellent. Thank you!

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.

4 participants