From: "Esteban Manchado Velázquez" Date: 2005-12-15T03:01:00+09:00 Subject: Re: #methods and #public_instance_methods --bg08WKrSYDhXBjb5 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi Jeff, On Thu, Dec 15, 2005 at 02:24:10AM +0900, Jeff Cohen wrote: > I'm trying to understand #methods and #public_instance_methods as I=20 > learn about introspection in Ruby. >=20 > If I do String.methods in irb, I get a lot fewer listed than if I try=20 > String.public_instance_methods. I would have guessed that=20 > String.public_instance_methods would be a subset of String.methods. >=20 > Also, ri String.public_instance_methods has no information, and=20 > public_instance_methods is not listed on ruby-doc.org/core. I only=20 > found it by doing a String.methods. >=20 > Can anyone shed some light here? #methods returns the list of methods callable for that _object_. That i= s, if you call String.methods, you get the methods for the String object (the object of class Class, if you prefer :-P ). #public_instance_methods, on the other hand, is a method defined for Cl= ass objects (perhaps some other, but anyway). It returns the methods callable f= or the _objects of that class_. E.g.: if String.methods return ['a', 'b', 'c'] and String.public_instance_methods return ['d', 'e', 'f'], you can call String.= a, String.b, String.c, "foo".d, "bar".e, "qux".f. You can also call String.public_instance_methods(false) if you only want the methods defined in the class String, but not inherited from String.superclass. HTH, --=20 Esteban Manchado Vel=E1zquez - http://www.foton.es EuropeSwPatentFree - http://EuropeSwPatentFree.hispalinux.es --bg08WKrSYDhXBjb5 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) iD8DBQFDoF3ShYgK5b1UDsERAhfYAJ0VI0xHacNHYvR3WzqAYgC5OZ+EvwCZAUMX PzcsqZfJg+sd0kDTglzBpho= =9Hyg -----END PGP SIGNATURE----- --bg08WKrSYDhXBjb5--