Skip to content

Commit 4af1f7e

Browse files
committed
Fix some errors in FAQ
1 parent bff9bf2 commit 4af1f7e

File tree

6 files changed

+24
-19
lines changed

6 files changed

+24
-19
lines changed

en/documentation/faq/11/index.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ fastest result.
5050
open("example").read.count("\n") # => 3
5151
~~~
5252

53-
### What do `begin` and `end` of `MatchingData` return?
53+
### What do `begin` and `end` of `MatchData` return?
5454

55-
They act with `$ `, and return the start index and the end index of the
56-
matched data (`$0`) in the original string. See an example in
55+
They act with `$~`, and return the start index and the end index of the
56+
matched data in the original string. See an example in
5757
[tab expansion](../9/#tab-expansion).
5858

5959
### How can I sum the elements in an array?

en/documentation/faq/4/index.md

+9-7
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,16 @@ end
123123
threads.each {|t| t.join }
124124
~~~
125125

126-
Produces:
126+
Might produce (in case the scheduler switches threads as hinted
127+
by `Thread.pass`; this depends on OS and processor):
127128

128129
~~~
129-
onetwo: : 00
130-
131-
onetwo: : 11
132-
133-
onetwo: : 33
130+
one: 0
131+
two: 0
132+
one: 1
133+
two: 1
134+
one: 3
135+
two: 3
134136
~~~
135137

136138
`while`, `until`, and `for` are control structures, not blocks, so local
@@ -195,7 +197,7 @@ A constant defined in a class or module definition can be accessed directly
195197
within that class's or module's definition.
196198

197199
You can directly access the constants in outer classes and modules from
198-
within nested classes and constants.
200+
within nested classes and modules.
199201

200202
You can also directly access constants in superclasses and included modules.
201203

en/documentation/faq/5/index.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def combine(*args)
194194
for it in args
195195
queue = SizedQueue.new(1)
196196
th = Thread.start(it, queue) do |i,q|
197-
self.send(it) do |x|
197+
self.send(i) do |x|
198198
q.push x
199199
end
200200
end
@@ -223,6 +223,6 @@ def it2 ()
223223
end
224224
225225
combine('it1','it2') do |x|
226-
# x is (1, 4), then (2, 5), then (3, 6)
226+
# x is [1, 4], then [2, 5], then [3, 6]
227227
end
228228
~~~

en/documentation/faq/7/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ change to it, and returns the copy. The version with the `!` modifies the
327327
receiver in place.
328328

329329
Beware, however, that there are a fair number of destructive methods that
330-
do not have an `!`, including assignment operators (`name=`), array assignment
330+
do not have an `!`, including assignment methods (`name=`), array assignment
331331
(`[]=`), and methods such as `Array.delete`.
332332

333333
### Why can destructive methods be dangerous?

en/documentation/faq/8/index.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,14 @@ way of extending the functionality associated with just one object.
177177
Take the lowly `Foo`:
178178

179179
~~~
180-
class Foo # => hello<<7>>nil
180+
class Foo
181181
def hello
182-
print "hello"
182+
"hello"
183183
end
184184
end
185185
186186
foo = Foo.new
187-
foo.hello
187+
foo.hello # => "hello"
188188
~~~
189189

190190
Now let's say we need to add class-level functionality to just this one
@@ -276,6 +276,9 @@ class MyClass
276276
def <=>(o)
277277
return @legs <=> o.legs
278278
end
279+
def inspect
280+
@name
281+
end
279282
end
280283
c = MyClass.new('cat', 4)
281284
s = MyClass.new('snake', 0)
@@ -337,7 +340,7 @@ is applied. A function-style method call implies `self` as the receiver.
337340

338341
### Why can't I load variables from a separate file?
339342

340-
Say `file1` contains:
343+
Say `file1.rb` contains:
341344

342345
~~~
343346
var1 = 99

en/documentation/faq/9/index.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -365,15 +365,15 @@ the destructive one has a suffix `!`.
365365

366366
~~~
367367
def foo(str)
368-
str = str.sub(/foo/, "baz")
368+
str.sub(/foo/, "baz")
369369
end
370370
371371
obj = "foo"
372372
foo(obj) # => "baz"
373373
obj # => "foo"
374374
375375
def foo(str)
376-
str = str.sub!(/foo/, "baz")
376+
str.sub!(/foo/, "baz")
377377
end
378378
379379
foo(obj) # => "baz"

0 commit comments

Comments
 (0)