dry-rb / dry-rb/dry-initializer

ordering of option declarations should not prohibit forward reference in default procs

Open
#97 6 comments 0 reactions 0 assignees View on GitHub
help wanted
Dominant language
Ruby
Stars
342
Forks
42
PR merge metrics
No merged PRs in 30d

Description

## Describe the bug

the :default keyword supports an "instance_exec" type of evaluation whereby `default: -> { foo + bar }' reference the object in questions' `foo` and ` bar` methods. however, when either `foo` or `bar` are, themselves, dry-initialized attributes, the default value will resolve to `nil` due to being referenced prior to 'dry initialization'

## To Reproduce

```ruby
require 'dry-initializer'

class A
extend Dry::Initializer
option :foo, default: -> { bar }
option :bar, default: -> { 42 }
end.new

class B
extend Dry::Initializer
option :bar, default: -> { 42 }
option :foo, default: -> { bar }
end.new

pp A.new #=> #
pp B.new #=> #

```

## Expected behavior

@bar == @foo == 42

## My environment

n/a

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.