summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-01-19 00:27:45 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-01-19 00:27:45 +0000
commit1ecaf599ff22d6102dde5b76699d78ec13758d88 (patch)
tree177163e842e01754d3cfe22c6e793d9de22a2e72
parent6ff1653cf6dc03d9ca5698c2247c8bb50e8bfd95 (diff)
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38881 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--doc/syntax/assignment.rdoc12
2 files changed, 17 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 4e87b80c40..cebd18faa4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Sat Jan 19 09:27:31 2013 Eric Hodel <drbrain@segment7.net>
+
+ * 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@segment7.net>
* doc/syntax/assignment.rdoc: Improved links
diff --git a/doc/syntax/assignment.rdoc b/doc/syntax/assignment.rdoc
index 830ba39ff0..c371593fbe 100644
--- a/doc/syntax/assignment.rdoc
+++ b/doc/syntax/assignment.rdoc
@@ -70,7 +70,17 @@ have not assigned to one of these ambiguous names ruby will assume you wish to
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