summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzzak <zzak@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-22 10:50:52 +0000
committerzzak <zzak@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-22 10:50:52 +0000
commitf13f9f694615780ef0d3d7741e84892d572d5be9 (patch)
tree6a8b9fa14fb61b221d2ef75ac37a9813467a898f
parentcf33a35a731aca2c3a9d8d7e24e25f3e8e3052f8 (diff)
* doc/syntax/methods.rdoc: [DOC] [] and []= methods by @process
[Fixes GH-662] https://github.com/ruby/ruby/pull/662 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47685 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--doc/syntax/methods.rdoc19
2 files changed, 24 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 9cfbf8cdc6..efb4c8f3a8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Mon Sep 22 19:49:12 2014 Zachary Scott <e@zzak.io>
+
+ * doc/syntax/methods.rdoc: [DOC] [] and []= methods by @process
+ [Fixes GH-662] https://github.com/ruby/ruby/pull/662
+
Mon Sep 22 18:21:35 2014 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
* .travis.yml: Only osx build is enabled. linux builds is random failure
diff --git a/doc/syntax/methods.rdoc b/doc/syntax/methods.rdoc
index 648843e753..58179549f3 100644
--- a/doc/syntax/methods.rdoc
+++ b/doc/syntax/methods.rdoc
@@ -109,6 +109,25 @@ operator with an <code>@</code> as in <code>+@</code> or <code>!@</code>:
Unary methods accept zero arguments.
+Additionally, methods for element reference and assignment may be defined:
+<code>[]</code> and <code>[]=</code> respectively. Both can take one or more
+arguments, and element reference can take none.
+
+ class C
+ def [](a, b)
+ puts a + b
+ end
+
+ def []=(a, b, c)
+ puts a * b + c
+ end
+ end
+
+ obj = C.new
+
+ obj[2, 3] # prints "5"
+ obj[2, 3] = 4 # prints "10"
+
== Return Values
By default, a method returns the last expression that was evaluated in the body