# Where is attr\_accessor located?

**URL:** <https://www.ruby-forum.com/t/where-is-attr-accessor-located/75723>\
**Category:** Ruby\
**Created:** [November 12, 2006, 7:16pm UTC](https://www.ruby-forum.com/t/where-is-attr-accessor-located/75723 "2006-11-12T19:16:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mariano\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@Mariano\_K](https://www.ruby-forum.com/u/Mariano_K)\
**Post date:** [November 12, 2006, 7:16pm UTC](https://www.ruby-forum.com/t/where-is-attr-accessor-located/75723/1 "2006-11-12T19:16:45Z")

</div>

Hi,

I am a bit confused. I get different responses when asking RI and  
IRB. It’s probably just me not understanding to read the output or  
issue the right queries.

When calling “ri attr\_accesor” I get the following:

## localhost:~ mkamp$ ri attr\_accessor --------------------------------------------------- Module#attr\_accessor attr\_accessor(symbol, …) =\> nil

```
  Equivalent to calling ``+attr+_symbol_+, true+'' on each _symbol_
  in turn.

     module Mod
       attr_accessor(:one, :two)
     end
     Mod.instance_methods.sort #=> ["one", "one=", "two", "two="]

```

That would mean attr\_accesor is in Module right?

Please look at this IRB session:

localhost:~ mkamp$ irb

> > Module.private\_methods.grep /attr/  
> > =\> [“attr”, “attr\_reader”, “attr\_writer”, “attr\_accessor”]
> 
> > Module.private\_methods(false).grep /attr/  
> > =\> []
> 
> > Kernel.private\_methods(false).grep /attr/  
> > =\> [“attr”, “attr\_reader”, “attr\_writer”, “attr\_accessor”]

Why is that? After looking at the rdoc documentation I would have  
assumed that attr\_accessor would be a private method of Module, not  
of Kernel.

Any idea?

Cheers,  
Mariano

---

<div class="post-metadata">

**Author:** ![Mariano\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@Mariano\_K](https://www.ruby-forum.com/u/Mariano_K)\
**Post date:** [November 12, 2006, 8:00pm UTC](https://www.ruby-forum.com/t/where-is-attr-accessor-located/75723/2 "2006-11-12T20:00:52Z")

</div>

On Sun, 12 Nov 2006 18:15:48 -0000, Mariano K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> After looking at the rdoc documentation I would have assumed that  
> attr\_accessor would be a private method of Module, not of Kernel.

It’s because:

Kernel.is\_a?(Module)

# =\> true

and the attr\* methods are instance methods on Module.

---

<div class="post-metadata">

**Author:** ![Mariano\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@Mariano\_K](https://www.ruby-forum.com/u/Mariano_K)\
**Post date:** [November 12, 2006, 10:17pm UTC](https://www.ruby-forum.com/t/where-is-attr-accessor-located/75723/3 "2006-11-12T22:17:19Z")

</div>

On Nov 12, 2006, at 8:00 PM, Ross B. wrote:

> > After looking at the rdoc documentation I would have assumed that  
> > attr\_accessor would be a private method of Module, not of Kernel.
> 
> It’s because:
> 
> Kernel.is\_a?(Module)
> 
> # =\> true
> 
> and the attr\* methods are instance methods on Module.

Yes, I _believe_ I understood that. It is “used” there.  
Maybe that is what I don’t get … Why doesn’t the method show up in  
Module?

Cheers,  
Mariano

---

<div class="post-metadata">

**Author:** ![Mariano\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@Mariano\_K](https://www.ruby-forum.com/u/Mariano_K)\
**Post date:** [November 13, 2006, 12:25am UTC](https://www.ruby-forum.com/t/where-is-attr-accessor-located/75723/4 "2006-11-13T00:25:37Z")

</div>

On Mon, Nov 13, 2006 at 06:16:05AM +0900, Mariano K. wrote:

> > and the attr\* methods are instance methods on Module.
> 
> Yes, I _believe_ I understood that. It is “used” there.  
> Maybe that is what I don’t get … Why doesn’t the method show up in  
> Module?

Module.is\_a? Class # =\> true  
Class.private\_instance\_methods(false).include? “attr\_reader” # =\>  
false  
Kernel.is\_a? Module # =\> true  
Module.private\_instance\_methods(false).include? “attr\_reader” # =\> true

---

<div class="post-metadata">

**Author:** ![Mariano\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@Mariano\_K](https://www.ruby-forum.com/u/Mariano_K)\
**Post date:** [November 13, 2006, 7:50am UTC](https://www.ruby-forum.com/t/where-is-attr-accessor-located/75723/5 "2006-11-13T07:50:07Z")

</div>

On Nov 13, 2006, at 12:24 AM, Mauricio F. wrote:

> Module.private\_instance\_methods(false).include? “attr\_reader” # =\>  
> true  
> Thanks, that was what I was looking for … Stupid of me 😉
