Where are Ruby's private methods documented online?

I can’t seem to find any documentation for for Ruby’s attr_accessor
method online? It is supposed to be in the Module class
(Class: Module (Ruby 1.9.3)).

I understand that the attr_* family of methods are private methods.

I found the private methods section for the Module class and the Object
class in the Pick Axe, but even there they are slightly hidden away
because in the Ruby Library Reference section (pg443 of 1.9 version)
private methods aren’t mentioned in the intro bit: “Standard classes are
listed alphabetically, followed by the standard modules. Within each, we
list the class (or module) methods, followed by its instance methods.”
But then it goes on to list private methods in the Module and Object
classes sections (only place private methods appear, I think?)

So where can I find attr_accessor in the official Ruby 1.9.3 online
docs?

And a few other related questions:
Is this a comprehensive list of the types of methods?
class
instance
private
protected
public (is public method the same as instance method?)

Are there any Ruby protected methods?

What’s the convention for writing a private method (a class method is
written e.g. Array::new, an instance method is written e.g. Array#pop)

Thx

On Tue, Apr 24, 2012 at 6:24 AM, b1_ __ [email protected] wrote:

listed alphabetically, followed by the standard modules. Within each, we
list the class (or module) methods, followed by its instance methods."
But then it goes on to list private methods in the Module and Object
classes sections (only place private methods appear, I think?)

So where can I find attr_accessor in the official Ruby 1.9.3 online
docs?

That’s pretty easy to find out:

  1. Find the class via any class (which is an instance of class Class):

$ ruby19 -e ‘p String.method(:attr_accessor)’
#<Method: Class(Module)#attr_accessor>
$ ruby19 -e ‘p Object.method(:attr_accessor)’
#<Method: Class(Module)#attr_accessor>

We see it’s defined in class Module.

  1. Get the documentation:

$ ri19 -T ‘Module#attr_accessor’
Module#attr_accessor

(from ruby core)

attr_accessor(symbol, …) → nil


Defines a named attribute for this module, where the name is
symbol.id2name, creating an instance variable (@name) and
a corresponding access method to read it. Also creates a method called
name= to set the attribute.

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

Note: -T only omits the pager.

And a few other related questions:
Is this a comprehensive list of the types of methods?
class
instance
private
protected
public (is public method the same as instance method?)

You are mixing orthogonal concepts. There are several lists:

  1. Visibility

private
protected
public

  1. Receiver

instance
class (which, strictly speaking, is also only an instance; but it
often does make sense to distinguish the two in order to make it clear
what state can be accessed)

Are there any Ruby protected methods?

Yes.

What’s the convention for writing a private method (a class method is
written e.g. Array::new, an instance method is written e.g. Array#pop)

Do you mean in discussions? There is no established convention for
visibility as far as I can see. Some UML tools use prefixes

public: +
protected: o
private: -

But generally referring to the visibility explicitly gives best
results in online discussions.

Kind regards

robert

On Mon, Apr 23, 2012 at 11:24 PM, b1_ __ [email protected] wrote:

listed alphabetically, followed by the standard modules. Within each, we
list the class (or module) methods, followed by its instance methods."
But then it goes on to list private methods in the Module and Object
classes sections (only place private methods appear, I think?)

So where can I find attr_accessor in the official Ruby 1.9.3 online
docs?

There are no official docs. I use rdoc.info and ruby-doc.org when it
fails
(they each have spotty results, but seem to cover each other’s holes).
If
you go to rdoc.info, select stdlib at the top, then core (first on the
list), choose to search for methods and then type “attr_accessor” into
the
search. It will give you a link to
http://rdoc.info/stdlib/core/1.9.3/Module#attr_accessor-instance_method

Okay guys, thx very much. Some more sources there I can look at to find
what I need.