Skip to content

Conversation

@jessevdp
Copy link

The ostruct gem is no longer a default gem in Ruby 4. See: release notes

Calling require 'ostruct' results in this message:

warning: ostruct used to be loaded from the standard library, but is not part of the default gems since Ruby 4.0.0. You can add ostruct to your Gemfile or gemspec to fix this error.

Followed by an error:

/path/to/ruby/4.0.0/bundled_gems.rb:60:in 'Kernel.require': cannot load such file -- ostruct (LoadError)

I also included some fixes to get the test suite up-and-running on Ruby 3+ and 4+:

  • Fix DeepOpenStruct for Ruby 3.0+ OpenStruct changes
  • Fix spec expectations for Ruby 3.0 keyword argument separation

The `ostruct` gem is no longer a default gem in Ruby 4. See: [release notes](https://www.ruby-lang.org/en/news/2025/12/25/ruby-4-0-0-released/#stdlib-updates)

Calling `require 'ostruct'` results in this message:

> warning: ostruct used to be loaded from the standard library, but is not part
> of the default gems since Ruby 4.0.0. You can add ostruct to your Gemfile or
> gemspec to fix this error.

Followed by an error:

```
/path/to/ruby/4.0.0/bundled_gems.rb:60:in 'Kernel.require': cannot load such file -- ostruct (LoadError)
```
Ruby 3.0 (via `ostruct` gem v0.3.0) removed the internal
`new_ostruct_member` method from `OpenStruct`. This was a
protected/internal method used to dynamically define accessor methods.

Replace manual `@table` manipulation with a simpler approach that
transforms the hash and delegates to `super()`.

References:
- ostruct gem versions: https://rubygems.org/gems/ostruct/versions
- Changes in ostruct 0.3.0: https://my.diffend.io/gems/ostruct/0.1.0/0.3.0
- Ruby/ostruct version mapping: https://stdgems.org/ostruct/
Ruby 3.0 enforces strict separation between positional hash arguments
and keyword arguments. RSpec matchers now distinguish between:

- `{ foo: :bar }` - positional hash argument
- `foo: :bar` - keyword arguments

Update test expectations to use explicit hash literals since the
production code passes options as positional hash arguments.

Reference:
https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/
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.

1 participant