@@ -77,7 +77,7 @@ Produces:
77
77
(Note that the class definition is executable code: the trace message it
78
78
contains is written as the class is defined).
79
79
80
- A block (`` {'' ... `` }'' or do ... end) almost introduces a new scope ;-)
80
+ A block (` { ... } ` or ` do ... end ` ) almost introduces a new scope ;-)
81
81
Locals created within a block are not accessible outside the block. However,
82
82
if a local within the block has the same name as an existing local variable
83
83
in the caller's scope, then no new local is created, and you can subsequently
@@ -126,10 +126,10 @@ is a method and the associated block introduces a new scope.
126
126
127
127
Actually, the question may be better asked as: "at what point does Ruby work
128
128
out that something is a variable?" The problem arises because the simple
129
- expression ``a'' could be either a variable or a call to a method with no
129
+ expression “a” could be either a variable or a call to a method with no
130
130
parameters. To decide which is the case, Ruby looks for assignment statements.
131
- If at some point in the source prior to the use of ``a'' it sees it being
132
- assigned to, it decides to parse ``a'' as a variable, otherwise it treats it
131
+ If at some point in the source prior to the use of “a” it sees it being
132
+ assigned to, it decides to parse “a” as a variable, otherwise it treats it
133
133
as a method. As a somewhat pathological case of this, consider this code
134
134
fragment, submitted by Clemens Hintze:
135
135
@@ -153,10 +153,10 @@ Produces:
153
153
Function 'a' called
154
154
a=99
155
155
156
- During the parse, Ruby sees the use of ``a'' in the first print statement and,
157
- as it hasn't yet seen any assignment to ``a'' , assumes that it is a method
156
+ During the parse, Ruby sees the use of “a” in the first print statement and,
157
+ as it hasn't yet seen any assignment to “a” , assumes that it is a method
158
158
call. By the time it gets to the second print statement, though, it has seen
159
- an assignment, and so treats ``a'' as a variable.
159
+ an assignment, and so treats “a” as a variable.
160
160
161
161
Note that the assignment does not have to be executed---Ruby just has to have
162
162
seen it. This program does not raise an error.
@@ -331,11 +331,11 @@ calls yield), or by using the Proc.call method.
331
331
a # -> "abcd"
332
332
A # -> "abcd"
333
333
334
- Variables hold references to objects. The assignment A = a = b = "abc" put a
335
- reference to the string `` abc'' into A, a, and b.
334
+ Variables hold references to objects. The assignment A = a = b = "abc" puts a
335
+ reference to the string “ abc” into A, a, and b.
336
336
337
337
When you called b.concat("d"), you invoked the concat method on that object,
338
- changing it from `` abc'' to `` abcd'' . Because a and A also reference that
338
+ changing it from “ abc” to “ abcd” . Because a and A also reference that
339
339
same object, their apparent value changes too.
340
340
341
341
This is less of a problem in practice than it might appear.
0 commit comments