From: Quintus Date: 2011-11-11T02:48:06+09:00 Subject: Re: Navigating through the official Ruby documentation -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Am 10.11.2011 18:22, schrieb Fily Salas: > Hi, Hi, > I have been trying to learn Ruby and so far so good I'm slowly > leering the basics. I was trying to start referring to the Docs but > I'm a little confused, I was expecting to see a list of all Ruby > classes and underneath the class name a list of all of its methods > but it has more than just methods, I don’t know if I still need > more knowledge about the language in order for me to understand the > information provided in the official Ruby Docs. Assuming you’re refering to http://ruby-doc.org/core-1.9.3/, it’s relatively easy. On the left side you have the "In Files" section. This tells you the names of the files inside the Ruby sourcecode where methods of your respective class are defined. For instance, for the Array class at http://ruby-doc.org/core-1.9.3/Array.html there are "array.c" and "pack.c" listed. This means, methods of this class are defined inside these files. Normally this shouldn't bother you, it's just an additional information (this can be useful in combination with gems if you don't know which files to require). On the right side you see the actual class/module documentation. > I see some methods start with a "#" some with "::" Those starting with # are instance methods, those starting with :: are class methods, i.e. methods you can call directly on the class. Array::new therefore is the same as Array.new (although the first form is AFAIK discouraged in actual code). The # is no valid Ruby syntax (if you try this, you’re likely to get syntax errors as this introduces a comment). > and than you have the following sections: In Files, See above. > Class/Module Index This is the list of all documented classes and modules, not just those related to e.g. Array. > Parent This is the parent class of the class you’re currently looking at. Look up what inheritance means if this isn’t clear to you. > I’m guessing this has to do with Modules vs Classes. No. Classes in Ruby are basically modules with the specific ability to create instances of themselves (via the ::new method). Sometimes, e.g. in the Array class, there’s also a section called "included modules". This lists all the modules that have been added to a class by using the Module#include method. Search for "mixins" if you want to know more on this. Both "Included modules" and "Parent" can list entities containing more methods than those of the class you’re looking at. For example, arrays have a method #max, but you won’t find this in the documentation of the Array class. It comes from the Enumerable module. Vale, Marvin -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJOvA4gAAoJELh1XLHFkqhavSgH+gMmGXQF+N1WyzcKkR0BRwCY W6eFe9oVr+oQV2EfSguwme/aJCPA3smq+9GkdpHkYVzE9S5+z+uEsYhOeXvvxsvM Nn4T2eTInlk+BrbiB/PxgE6O23GbZO2078pEyKRHXA26FaMSAgq5gg2N7feAHA2N /0v9/EiTh7OEefijQvp28VFthwZt+3/Im5pT0oGCo/dv6qs15xKINm/duiCbshW6 vgyID9Adidh9qEXgf0+lvjV1p/N6O9JKrL4LkssLf1xQefORtXgdg8EerMkV6tib Rh2DX+4+P+myyHW6hgxgzSSMsQM6ng+g4OtiCErAWzsNvig8Av2FmhLBQcfatO8= =ABU+ -----END PGP SIGNATURE-----