# Dry::Struct default from another attribute using a lambda

**URL:** <https://discourse.dry-rb.org/t/dry-struct-default-from-another-attribute-using-a-lambda/504>\
**Category:** Support\
**Created:** [March 7, 2018, 5:19pm UTC](https://discourse.dry-rb.org/t/dry-struct-default-from-another-attribute-using-a-lambda/504 "2018-03-07T17:19:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gottfrois](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/gottfrois/32/190_2.png) [@gottfrois](https://discourse.dry-rb.org/u/gottfrois)\
**Post date:** [March 7, 2018, 5:19pm UTC](https://discourse.dry-rb.org/t/dry-struct-default-from-another-attribute-using-a-lambda/504/1 "2018-03-07T17:19:52Z")

</div>

Hey guys,

I wanted to be able to define a struct with an attribute that defaults on the value of another attribute within the same struct:

```ruby
class Foo < Dry::Struct
  attribute :requested_by_id, Types::String
  attribute :executed_by_id, Types::String.optional.default(->(foo) { foo.requested_by_id }) 
end 

```

Though `default` does not seem to accept a block.  
Any idea how to achieve this?

---

<div class="post-metadata">

**Author:** ![solnic](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/solnic/32/779_2.png) [@solnic](https://discourse.dry-rb.org/u/solnic)\
**Post date:** [March 7, 2018, 6:04pm UTC](https://discourse.dry-rb.org/t/dry-struct-default-from-another-attribute-using-a-lambda/504/2 "2018-03-07T18:04:56Z")

</div>

This won’t be supported. You can achieve something similar by simply defining a method:

```ruby
def executed_by_id
  @executed_by_id || requested_by_id
end

```

Alternatively, you can override `.new` and set the default value there.
