# \[Dry::Struct\] Reusing a set of common attributes

**URL:** https://discourse.dry-rb.org/t/dry-struct-reusing-a-set-of-common-attributes/315
**Category:** dry-types
**Created:** [July 19, 2017, 7:25pm UTC](https://discourse.dry-rb.org/t/dry-struct-reusing-a-set-of-common-attributes/315 "2017-07-19T19:25:34Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![Vincent](https://avatars.discourse-cdn.com/v4/letter/v/e9bcb4/32.png) [@Vincent](https://discourse.dry-rb.org/u/Vincent)
#### Post date: [July 23, 2017, 3:15pm UTC](https://discourse.dry-rb.org/t/dry-struct-reusing-a-set-of-common-attributes/315/3 "2017-07-23T15:15:46Z")

</div>

I ended up with the following version:

require ‘dry-struct’

```
module Types
  include Dry::Types.module
  
  Uuid = Types::String
                  .constructor(&:upcase)
                  .constrained(format: /^[0-9A-F]{8}-[0-9A-F]{4}-[1-5][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/)
end

module CommonAttributes
  def self.included(mod)
    mod::attribute :uuid, Types::Uuid
  end
end

class StructA < Dry::Struct::Value
  include CommonAttributes
  attribute :attr_a, Types::String
end

class StructB < Dry::Struct
  include CommonAttributes
  attribute :attr_b, Types::String
end

```

Cheers!

---

_[View the full topic](https://discourse.dry-rb.org/t/dry-struct-reusing-a-set-of-common-attributes/315)._
