Skip to content

Freeze is not working + add deep freeze / immutable #61

@kke

Description

@kke

Freeze does not work:

> r = RecursiveOpenStruct.new( { hello: 'world', foo: [ {bar: :baz} ] }, recurse_over_arrays: true)
> r.freeze
> r.delete_field('foo')
> r
=> #<RecursiveOpenStruct hello="world">
> r.bar = 'baz'
> r
=> #<RecursiveOpenStruct hello="world", bar="baz">

Deep freeze would be nice:

> r = RecursiveOpenStruct.new( { hello: 'world', foo: [ {bar: :baz} ] }, recurse_over_arrays: true)
> r.deep_freeze
> r.hello.reverse!
FrozenError (can't modify frozen String)
> r.foo << { dog: :cat }
FrozenError (can't modify frozen Array)
> r.foo.first.bar = :closed
FrozenError (can't modify frozen RecursiveOpenStruct)

This could be done after initialization if immutable: true has been given:

> r = RecursiveOpenStruct.new( { hello: 'world', foo: [ {bar: :baz} ] }, recurse_over_arrays: true, immutable: true)
> r.hello = 'universe'
FrozenError (can't modify frozen RecursiveOpenStruct)
> r.foo << { dog: :cat }
FrozenError (can't modify frozen Array)
> r.foo.first.bar = :closed
FrozenError (can't modify frozen RecursiveOpenStruct)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions