# Extend Class to include attr?

**URL:** <https://www.ruby-forum.com/t/extend-class-to-include-attr/186975>\
**Category:** Ruby\
**Created:** [April 15, 2010, 5:31am UTC](https://www.ruby-forum.com/t/extend-class-to-include-attr/186975 "2010-04-15T05:31:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 15, 2010, 5:31am UTC](https://www.ruby-forum.com/t/extend-class-to-include-attr/186975/1 "2010-04-15T05:31:07Z")

</div>

Can I extend a class to add an attr\_accessor?  
So that getter & setter are created?

MarkT

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 15, 2010, 8:01am UTC](https://www.ruby-forum.com/t/extend-class-to-include-attr/186975/2 "2010-04-15T08:01:33Z")

</div>

On 15.04.2010 05:30, Mark T wrote:

> Can I extend a class to add an attr\_accessor?  
> So that getter& setter are created?

Yes.

> How?

class AnyClass  
attr\_accessor :foo  
end

Kind regards

robert
