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

ruby-changes:26829

From: drbrain <ko1@a...>
Date: Sat, 19 Jan 2013 09:29:47 +0900 (JST)
Subject: [ruby-changes:26829] drbrain:r38881 (trunk): * doc/syntax/assignment.rdoc (Local Variables and Methods): Made it

drbrain	2013-01-19 09:27:45 +0900 (Sat, 19 Jan 2013)

  New Revision: 38881

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

  Log:
    * doc/syntax/assignment.rdoc (Local Variables and Methods):  Made it
      more clear that local variables are created by the parser, not
      execution.  Thanks to John Hawthorn.

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

Index: doc/syntax/assignment.rdoc
===================================================================
--- doc/syntax/assignment.rdoc	(revision 38880)
+++ doc/syntax/assignment.rdoc	(revision 38881)
@@ -70,7 +70,17 @@ have not assigned to one of these ambigu https://github.com/ruby/ruby/blob/trunk/doc/syntax/assignment.rdoc#L70
 call a method.  Once you have assigned to the name ruby will assume you wish
 to reference a local variable.
 
-This leads to some potentially confusing code, for example:
+The local variable is created when the parser encounters the assignment, not
+when the assignment occurs:
+
+  a = 0 if false # does not assign to a
+
+  p local_variables # prints [:a]
+
+  p a # prints nil
+
+The similarity between method and local variable names can lead to confusing
+code, for example:
 
   def big_calculation
     42 # pretend this takes a long time
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38880)
+++ ChangeLog	(revision 38881)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Jan 19 09:27:31 2013  Eric Hodel  <drbrain@s...>
+
+	* doc/syntax/assignment.rdoc (Local Variables and Methods):  Made it
+	  more clear that local variables are created by the parser, not
+	  execution.  Thanks to John Hawthorn.
+
 Sat Jan 19 09:15:58 2013  Eric Hodel  <drbrain@s...>
 
 	* doc/syntax/assignment.rdoc:  Improved links

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

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