ruby-changes:35603
From: zzak <ko1@a...>
Date: Mon, 22 Sep 2014 19:50:57 +0900 (JST)
Subject: [ruby-changes:35603] zzak:r47685 (trunk): * doc/syntax/methods.rdoc: [DOC] [] and []= methods by @process
zzak 2014-09-22 19:50:52 +0900 (Mon, 22 Sep 2014) New Revision: 47685 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47685 Log: * doc/syntax/methods.rdoc: [DOC] [] and []= methods by @process [Fixes GH-662] https://github.com/ruby/ruby/pull/662 Modified files: trunk/ChangeLog trunk/doc/syntax/methods.rdoc Index: doc/syntax/methods.rdoc =================================================================== --- doc/syntax/methods.rdoc (revision 47684) +++ doc/syntax/methods.rdoc (revision 47685) @@ -109,6 +109,25 @@ operator with an <code>@</code> as in <c https://github.com/ruby/ruby/blob/trunk/doc/syntax/methods.rdoc#L109 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 Index: ChangeLog =================================================================== --- ChangeLog (revision 47684) +++ ChangeLog (revision 47685) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Sep 22 19:49:12 2014 Zachary Scott <e@z...> + + * 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@g...> * .travis.yml: Only osx build is enabled. linux builds is random failure -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/