# Dry::Struct attribute alias

**URL:** <https://discourse.dry-rb.org/t/dry-struct-attribute-alias/480>\
**Category:** Ideas\
**Created:** [February 20, 2018, 11:23am UTC](https://discourse.dry-rb.org/t/dry-struct-attribute-alias/480 "2018-02-20T11:23:11Z")\
**Posts on this page:** 5\
**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:** [February 20, 2018, 11:23am UTC](https://discourse.dry-rb.org/t/dry-struct-attribute-alias/480/1 "2018-02-20T11:23:11Z")

</div>

Would be nice to be able to define an alias for a given attribute on dry-struct:

```ruby
class Foo < Dry::Struct
  attribute :id, Types::String, as: :some_alias_name 
end

```

---

<div class="post-metadata">

**Author:** ![timriley](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/timriley/32/25_2.png) [@timriley](https://discourse.dry-rb.org/u/timriley)\
**Post date:** [February 20, 2018, 10:12pm UTC](https://discourse.dry-rb.org/t/dry-struct-attribute-alias/480/2 "2018-02-20T22:12:33Z")

</div>

@gottfrois Given how easy this is to do with Ruby’s built-in `alias_method`, or something similar, I’m not sure this kind of thing would make its way into the gem. Do you need to alias very often?

---

<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:** [February 21, 2018, 2:23pm UTC](https://discourse.dry-rb.org/t/dry-struct-attribute-alias/480/3 "2018-02-21T14:23:36Z")

</div>

Not really, we just needed an easy way to alias this `id` attribute. Now, using `alias_method` works fine, it’s just more intuitive to have this at the time you define the attribute rather than couple lines later IMO.

---

<div class="post-metadata">

**Author:** ![timriley](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/timriley/32/25_2.png) [@timriley](https://discourse.dry-rb.org/u/timriley)\
**Post date:** [February 21, 2018, 10:03pm UTC](https://discourse.dry-rb.org/t/dry-struct-attribute-alias/480/4 "2018-02-21T22:03:11Z")

</div>

@gottfrois Fair enough. If it’s important for you, you could always make your app’s own struct superclass that inherits from dry-struct and overrides `.attribute` with support for setting the alias.

---

<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 2, 2018, 10:14am UTC](https://discourse.dry-rb.org/t/dry-struct-attribute-alias/480/5 "2018-03-02T10:14:58Z")

</div>

dry-struct will never support options, I won’t repeat the same mistake like in Virtus.
