[前][次][番号順一覧][スレッド一覧]

ruby-changes:26370

From: drbrain <ko1@a...>
Date: Mon, 17 Dec 2012 12:05:56 +0900 (JST)
Subject: [ruby-changes:26370] drbrain:r38421 (trunk): * doc/syntax/methods.rdoc: Added a description of singleton methods.

drbrain	2012-12-17 12:05:45 +0900 (Mon, 17 Dec 2012)

  New Revision: 38421

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38421

  Log:
    * doc/syntax/methods.rdoc:  Added a description of singleton methods.

  Modified files:
    trunk/ChangeLog
    trunk/doc/syntax/methods.rdoc

Index: doc/syntax/methods.rdoc
===================================================================
--- doc/syntax/methods.rdoc	(revision 38420)
+++ doc/syntax/methods.rdoc	(revision 38421)
@@ -11,6 +11,27 @@ A method definition consists of the +def https://github.com/ruby/ruby/blob/trunk/doc/syntax/methods.rdoc#L11
 the method, then the +end+ keyword.  When called the method will execute the
 body of the method.  This method returns <tt>2</tt>.
 
+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:
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38420)
+++ ChangeLog	(revision 38421)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Dec 17 12:05:32 2012  Eric Hodel  <drbrain@s...>
+
+	* doc/syntax/methods.rdoc:  Added a description of singleton methods.
+
 Mon Dec 17 11:35:57 2012  Eric Hodel  <drbrain@s...>
 
 	* doc/.document:  Added doc/syntax

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]