Where is attr_accessor located?

M

Mariano Kamp

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
 
M

Mauricio Fernandez

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top