Skip to content

Commit 40c0116

Browse files
committed
Rewrap; remove trailing whitespace
1 parent fba3735 commit 40c0116

File tree

11 files changed

+817
-328
lines changed

11 files changed

+817
-328
lines changed

en/documentation/faq/10/index.md

+32-13
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ header: |
3535

3636
10.1 How can I use Ruby interactively?
3737

38-
You can try using irb. The following is paraphrased from Goto Kentaro (Gotoken), and originally appeared in ruby-talk:444.
38+
You can try using irb. The following is paraphrased from Goto Kentaro
39+
(Gotoken), and originally appeared in ruby-talk:444.
3940

4041
Get the latest tarball of irb from the contrib directory in the Ruby archive.
4142
Extract the irb directory tree.
@@ -45,48 +46,66 @@ You can try using irb. The following is paraphrased from Goto Kentaro (Gotoken),
4546
Possibly use rehash to tell your login shell about the new command.
4647
Type irb
4748

48-
If the readline extension module works with your interpreter, it makes irb a lot more fun to use.
49+
If the readline extension module works with your interpreter, it makes irb
50+
a lot more fun to use.
51+
52+
There is also a simple program, eval, in the samples/ directory of the Ruby
53+
distribution. It lets you enter expressions and view their values. You can
54+
copy eval into the site_ruby directory in the Ruby tree, and then invoke it
55+
using:
4956

50-
There is also a simple program, eval, in the samples/ directory of the Ruby distribution. It lets you enter expressions and view their values. You can copy eval into the site_ruby directory in the Ruby tree, and then invoke it using:
5157

52-
5358

5459
ruby -r eval -e0
5560

5661
10.2 Is there a debugger for Ruby?
5762

5863
There is a gdb-like debugger for Ruby.
5964

60-
65+
6166

6267
ruby -r debug your_program
6368

6469
10.3 How can I use a library written in C from Ruby?
6570

66-
Of all the scripting languages, Ruby is probably the easiest to extend. There are no problems with reference counting and variable types, and very few interfaces to learn. In fact, C code used to extend Ruby often ends up looking surprisingly like Ruby code itself.
71+
Of all the scripting languages, Ruby is probably the easiest to extend.
72+
There are no problems with reference counting and variable types, and very
73+
few interfaces to learn. In fact, C code used to extend Ruby often ends up
74+
looking surprisingly like Ruby code itself.
6775

68-
First, get the Ruby source distribution and read README.EXT. This is a good document, not only if you're writing an extension library, but also if you want to understand Ruby more deeply.
76+
First, get the Ruby source distribution and read README.EXT. This is a good
77+
document, not only if you're writing an extension library, but also if you
78+
want to understand Ruby more deeply.
6979

70-
Next, have a look at the source of the interpreter itself, and at the various supplied extensions in the ext/ directory. You'll also find good examples under contrib/ on the Ruby ftp sites.
80+
Next, have a look at the source of the interpreter itself, and at the various
81+
supplied extensions in the ext/ directory. You'll also find good examples
82+
under contrib/ on the Ruby ftp sites.
7183

7284
10.4 Can I use Tcl/Tk interface in Ruby?
7385

74-
There are two interfaces to Tcl/Tk included in the standard distribution. One is under ext/tcltk/ and loaded with require "tcltk". The syntax is very close to that Tcl, which is passed to Tcl interpreter. Unfortunately, the description for this library is written in Japanese.
86+
There are two interfaces to Tcl/Tk included in the standard distribution.
87+
One is under ext/tcltk/ and loaded with require "tcltk". The syntax is very
88+
close to that Tcl, which is passed to Tcl interpreter. Unfortunately, the
89+
description for this library is written in Japanese.
7590

76-
The other is under ext/tk/ and loaded with require "tk". Its syntax closer to the style of the Tk interface provided by the Perl and Python interfaces.
91+
The other is under ext/tk/ and loaded with require "tk". Its syntax closer to
92+
the style of the Tk interface provided by the Perl and Python interfaces.
7793

7894
10.5 Tk won't work.
7995

8096
Your Tk version may be old, try a newer version.
8197

8298
10.6 Can I use gtk+ or xforms interfaces in Ruby?
8399

84-
You'll find ruby-gtk-x.xx.tar.gz and ruby-forms-x.x.tar.gz under contrib/ in ftp sites.
100+
You'll find ruby-gtk-x.xx.tar.gz and ruby-forms-x.x.tar.gz under contrib/
101+
in ftp sites.
85102

86103
10.7 How can I do date arithmetic?
87104

88105
A Time object can express only the dates between Jan 1, 1970 and Jan 19, 2038.
89106

90-
Two standard extension library modules are provided: require "date", which is simple and uses the English calendar, and require "date2", which is more general purpose.
107+
Two standard extension library modules are provided:
108+
require "date", which is simple and uses the English calendar,
109+
and require "date2", which is more general purpose.
91110

92-
Also see sample/cal.rb.
111+
Also see sample/cal.rb.

en/documentation/faq/11/index.md

+29-17
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,26 @@ It's the same as saying if a then b else c end.
3939

4040
11.2 How can I count the number of lines in a file?
4141

42-
Assuming that the file ends in a linefeed, the following code may give the fastest result.
42+
Assuming that the file ends in a linefeed, the following code may give the
43+
fastest result.
44+
4345

44-
4546

4647
open("example").read.count("\n") # -> 3
4748

4849
11.3 What do begin and end of MatchingData return?
4950

50-
They act with $ , and return the start index and the end index of the matched data ($0) in the original string. See an example in tab expansion.
51+
They act with $ , and return the start index and the end index of the
52+
matched data ($0) in the original string. See an example in tab expansion.
5153

5254
11.4 How can I sum the elements in an array?
5355

54-
Rather than solve the specific problem, let's solve the general case. The first thing we'll do is produce a method that will iterate over an Enumerable object and collect a single result. Smalltalk calls that method inject, so we will too:
56+
Rather than solve the specific problem, let's solve the general case. The
57+
first thing we'll do is produce a method that will iterate over an Enumerable
58+
object and collect a single result. Smalltalk calls that method inject, so we
59+
will too:
60+
5561

56-
5762

5863
module Enumerable
5964

@@ -66,9 +71,14 @@ module Enumerable
6671
end
6772
end
6873

69-
Notice how we've added the method to Enumerable. This means that anything that includes Enumerable can now use inject. But how do we use it? It takes a single argument `n' and a block. For each element in the thing being enumerated, it calls the block, passing in `n' and the element itself. The result of the block is assigned back to `n'. So, to define sum, we could write:
74+
Notice how we've added the method to Enumerable. This means that anything
75+
that includes Enumerable can now use inject. But how do we use it? It takes
76+
a single argument `n' and a block. For each element in the thing being
77+
enumerated, it calls the block, passing in `n' and the element itself.
78+
The result of the block is assigned back to `n'. So, to define sum,
79+
we could write:
80+
7081

71-
7282

7383
module Enumerable
7484
def sum
@@ -81,11 +91,15 @@ end
8191

8292
11.5 How can I use continuations?
8393

84-
Ruby's continuations allow you to create an object representing a place in a Ruby program, and then return to that place at any time (even if it has apparently gone out of scope). Continuations can be used to implement complex control structures, but are typically more useful as ways of confusing people.
94+
Ruby's continuations allow you to create an object representing a place in a
95+
Ruby program, and then return to that place at any time (even if it has
96+
apparently gone out of scope). Continuations can be used to implement complex
97+
control structures, but are typically more useful as ways of confusing people.
98+
99+
In [ruby-talk:4482], Jim Weirich posted the following examples of
100+
continuations:
85101

86-
In [ruby-talk:4482], Jim Weirich posted the following examples of continuations:
87102

88-
89103

90104
# --------------------------------------------------------------------
91105
# Simple Producer/Consumer
@@ -114,14 +128,14 @@ def count(limit)
114128
print "\n"
115129
end
116130

117-
131+
118132

119133
# --------------------------------------------------------------------
120134
# Filtering Out Multiples of a Given Number
121135
# --------------------------------------------------------------------
122-
# Create a filter that is both a consumer and producer. Insert it
136+
# Create a filter that is both a consumer and producer. Insert it
123137
# between the counting task and the printing task.
124-
#
138+
#
125139
# Usage: omit (2, limit)
126140

127141
def filter_task(factor, consumer)
@@ -139,12 +153,12 @@ def omit(factor, limit)
139153
print "\n"
140154
end
141155

142-
156+
143157

144158
# --------------------------------------------------------------------
145159
# Prime Number Generator
146160
# --------------------------------------------------------------------
147-
# Create a prime number generator. When a new prime number is
161+
# Create a prime number generator. When a new prime number is
148162
# discovered, dynamically add a new multiple filter to the chain of
149163
# producers and consumers.
150164
#
@@ -165,5 +179,3 @@ def primes(limit)
165179
count_task(limit, primes)
166180
print "\n"
167181
end
168-
169-

en/documentation/faq/2/index.md

+53-9
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,68 @@ header: |
3030
<h1>Official Ruby FAQ</h1>
3131
3232
---
33+
3334
## How Does Ruby Stack Up Against...?
3435

3536
### How Does Ruby Compare With Python?
3637

37-
Python and Ruby are both object oriented languages that provide a smooth transition from procedural to OO programming styles. Smalltalk, by contrast, is object only - you can't do anything until you understand objects, inheritance and the sizable Smalltalk class hierarchy. By providing procedural training wheels, Python and Ruby ``fix'' one of the features that may have kept Smalltalk out of the mainstream. The two languages differ by approaching this solution from opposite directions.
38+
Python and Ruby are both object oriented languages that provide a smooth
39+
transition from procedural to OO programming styles. Smalltalk, by contrast,
40+
is object only - you can't do anything until you understand objects,
41+
inheritance and the sizable Smalltalk class hierarchy. By providing procedural
42+
training wheels, Python and Ruby ``fix'' one of the features that may have
43+
kept Smalltalk out of the mainstream. The two languages differ by approaching
44+
this solution from opposite directions.
3845

39-
Python is a hybrid language. It has functions for procedural programming and objects for OO programming. Python bridges the two worlds by allowing functions and methods to interconvert using the explicit ``self'' parameter of every method def. When a function is inserted into an object, the first argument automagically becomes a reference to the receiver.
46+
Python is a hybrid language. It has functions for procedural programming and
47+
objects for OO programming. Python bridges the two worlds by allowing
48+
functions and methods to interconvert using the explicit ``self'' parameter
49+
of every method def. When a function is inserted into an object, the first
50+
argument automagically becomes a reference to the receiver.
4051

41-
Ruby is a pure OO language that can masquerade as a procedural one. It has no functions, only method calls. In a Ruby method the receiver, also called self, is a hidden argument like ``this'' in C++. A ``def'' statement outside of a class definition, which is a function in Python, is actually a method call in Ruby. These ersatz functions become private methods of class Object, the root of the Ruby class hierarchy. Procedural programming is neatly solved from the other direction - everything is an object. If the user doesn't grok objects yet, they can just pretend that ``def'' is a function definition and still get useful work done.
52+
Ruby is a pure OO language that can masquerade as a procedural one. It has no
53+
functions, only method calls. In a Ruby method the receiver, also called self,
54+
is a hidden argument like ``this'' in C++. A ``def'' statement outside of a
55+
class definition, which is a function in Python, is actually a method call in
56+
Ruby. These ersatz functions become private methods of class Object, the root
57+
of the Ruby class hierarchy. Procedural programming is neatly solved from the
58+
other direction - everything is an object. If the user doesn't grok objects
59+
yet, they can just pretend that ``def'' is a function definition and still
60+
get useful work done.
4261

43-
Ruby's OO purity provides a number features that Python lacks or is still working toward: a unified type/class hierarchy, metaclasses, the ability to subclass everything, and uniform method invocation (none of this len() is a function but items() is a method rubbish). Ruby, like Smalltalk, only supports single inheritance, but it does have a very powerful mixin concept: a class definition may include a module, which inserts that module's methods, constants, etc. into the class.
62+
Ruby's OO purity provides a number features that Python lacks or is still
63+
working toward: a unified type/class hierarchy, metaclasses, the ability to
64+
subclass everything, and uniform method invocation (none of this len() is a
65+
function but items() is a method rubbish). Ruby, like Smalltalk, only supports
66+
single inheritance, but it does have a very powerful mixin concept: a class
67+
definition may include a module, which inserts that module's methods,
68+
constants, etc. into the class.
4469

45-
Ruby, again like Smalltalk, provides closures and code blocks and uses them to the same good effect. The Ruby collection classes and iterators are outstanding, much more powerful and elegant than the ad hoc solutions that Python is sprouting (lambdas and list comprehensions).
70+
Ruby, again like Smalltalk, provides closures and code blocks and uses them
71+
to the same good effect. The Ruby collection classes and iterators are
72+
outstanding, much more powerful and elegant than the ad hoc solutions that
73+
Python is sprouting (lambdas and list comprehensions).
4674

47-
Ruby's syntax and design philosophy are heavily influenced by Perl. It has a lot of syntactic variability. Statement modifiers (if, unless, while, until, etc.) may appear at the end of any statement. Some key words are optional (the ``then'' in an ``if'' statement for example). Parentheses may sometimes be elided in method calls. The receiver of a method may usually be elided. Many, many things are lifted directly from Perl. Built in regular expressions, $_ and friends, here documents, the single-quoted / double-quoted string distinction, $ and @ prefixes to distinguish different kinds of names and so forth.
75+
Ruby's syntax and design philosophy are heavily influenced by Perl. It has a
76+
lot of syntactic variability. Statement modifiers (if, unless, while, until,
77+
etc.) may appear at the end of any statement. Some key words are optional
78+
(the ``then'' in an ``if'' statement for example). Parentheses may sometimes
79+
be elided in method calls. The receiver of a method may usually be elided.
80+
Many, many things are lifted directly from Perl.
81+
Built in regular expressions, $_ and friends, here documents,
82+
the single-quoted / double-quoted string distinction, $ and @ prefixes
83+
to distinguish different kinds of names and so forth.
4884

49-
If you like Perl, you will like Ruby and be right at home with its syntax. If you like Smalltalk, you will like Ruby and be right at home with its semantics. If you like Python, you may or may not be put off by the huge difference in design philosophy between Python and Ruby/Perl.
85+
If you like Perl, you will like Ruby and be right at home with its syntax.
86+
If you like Smalltalk, you will like Ruby and be right at home with its
87+
semantics. If you like Python, you may or may not be put off by the huge
88+
difference in design philosophy between Python and Ruby/Perl.
5089

51-
Ruby is much more complex than Python but its features, for the most part, hang together well. Ruby is well designed and full of neat ideas that might be mined for P3K. I'm not sure how many Python programmers will be attracted to it though - it hasn't won me over (yet). But it is worthy of serious study and could be a real threat to Perl.
90+
Ruby is much more complex than Python but its features, for the most part,
91+
hang together well. Ruby is well designed and full of neat ideas that might be
92+
mined for P3K. I'm not sure how many Python programmers will be attracted to
93+
it though - it hasn't won me over (yet). But it is worthy of serious study and
94+
could be a real threat to Perl.
5295

53-
Posted by John Dell'Aquila in comp.lang.python, 11/17/2000. Reproduced with permission.
96+
Posted by John Dell'Aquila in comp.lang.python, 11/17/2000. Reproduced with
97+
permission.

0 commit comments

Comments
 (0)