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

ruby-changes:48182

From: hsbt <ko1@a...>
Date: Sun, 22 Oct 2017 00:19:50 +0900 (JST)
Subject: [ruby-changes:48182] hsbt:r60295 (trunk): Clarify return value for assignment methods.

hsbt	2017-10-22 00:19:45 +0900 (Sun, 22 Oct 2017)

  New Revision: 60295

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60295

  Log:
    Clarify return value for assignment methods.
    
      https://github.com/ruby/ruby/pull/1682
    
      Patch by @sos4nt [fix GH-1682]

  Modified files:
    trunk/doc/syntax/methods.rdoc
Index: doc/syntax/methods.rdoc
===================================================================
--- doc/syntax/methods.rdoc	(revision 60294)
+++ doc/syntax/methods.rdoc	(revision 60295)
@@ -147,7 +147,7 @@ evaluated. https://github.com/ruby/ruby/blob/trunk/doc/syntax/methods.rdoc#L147
     1 + 1  # this expression is never evaluated
   end
 
-Note that for assignment methods the return value will always be ignored.
+Note that for assignment methods the return value will be ignored when using the assignment syntax.
 Instead, the argument will be returned:
 
   def a=(value)
@@ -155,6 +155,10 @@ Instead, the argument will be returned: https://github.com/ruby/ruby/blob/trunk/doc/syntax/methods.rdoc#L155
   end
 
   p(a = 5) # prints 5
+  
+The actual return value will be returned when invoking the method directly:
+
+  p send(:a=, 5) # prints 6
 
 == Scope
 

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

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