From 73b244d0ded191337ed6b30eb7ead658b614ae8b Mon Sep 17 00:00:00 2001 From: drbrain Date: Mon, 17 Dec 2012 03:05:45 +0000 Subject: * doc/syntax/methods.rdoc: Added a description of singleton methods. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38421 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ doc/syntax/methods.rdoc | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/ChangeLog b/ChangeLog index 2be56c7471..ba1794a796 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Mon Dec 17 12:05:32 2012 Eric Hodel + + * doc/syntax/methods.rdoc: Added a description of singleton methods. + Mon Dec 17 11:35:57 2012 Eric Hodel * doc/.document: Added doc/syntax diff --git a/doc/syntax/methods.rdoc b/doc/syntax/methods.rdoc index c207649264..88a4378af8 100644 --- a/doc/syntax/methods.rdoc +++ b/doc/syntax/methods.rdoc @@ -11,6 +11,27 @@ A method definition consists of the +def+ keyword, a method name, the body of the method, then the +end+ keyword. When called the method will execute the body of the method. This method returns 2. +A method may be defined on another object. You may define a "class +method" (a method that is called on the class, not an instance of the class) +like this: + + class C + def self.my_method + # ... + end + end + +You may also define methods this way on any object: + + string = "my string" + def string.my_method + # ... + end + +This is called a "singleton method". +my_method+ will only exist on this +string instance. Other strings will not have +my_method+. You may also +override existing methods on just one object this way. + == Arguments A method may accept arguments. The argument list follows the method name: -- cgit v1.2.3