# Cattr\_accessor for all attributes

**URL:** <https://www.ruby-forum.com/t/cattr-accessor-for-all-attributes/159548>\
**Category:** Rails\
**Created:** [February 5, 2009, 5:02pm UTC](https://www.ruby-forum.com/t/cattr-accessor-for-all-attributes/159548 "2009-02-05T17:02:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/4da419/32.png) [@bide](https://www.ruby-forum.com/u/bide)\
**Post date:** [February 5, 2009, 5:02pm UTC](https://www.ruby-forum.com/t/cattr-accessor-for-all-attributes/159548/1 "2009-02-05T17:02:44Z")

</div>

Hi,

I´ve created an “acts\_as” plugin where the user can add several  
attributes of his choice to the model.  
Now I´m looking for a way to allow the users to access all attributes  
without changing the plugin code

e.g., now I set the accessors like this in the plugin code:  
cattr\_accessor :first\_name, last\_name

I am looking for something like this:  
attr\_accessor :all

Thanks for your help,  
bide

---

<div class="post-metadata">

**Author:** ![bide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/4da419/32.png) [@bide](https://www.ruby-forum.com/u/bide)\
**Post date:** [February 6, 2009, 1:03am UTC](https://www.ruby-forum.com/t/cattr-accessor-for-all-attributes/159548/2 "2009-02-06T01:03:21Z")

</div>

obj.instance\_variables might be the answer you are looking for,  
although attr\_accessor :name will not create the corresponding  
instance variable.

Also, are you sure :first\_name and :last\_name should be class  
attribute accessors and not instance ones (so plain attr\_accessors)?

Balint
