@@ -1794,9 +1794,11 @@ end
17941794
17951795Defines the class `C` which inherits from `SuperClass`
17961796
1797- クラスについては第一部でかなりしつこく説明した。実行される文であること、
1798- 文内では定義中のクラスが`self`になること、本体には任意の式が書けること、
1799- クラス定義文はネストできること。いずれもRubyの実行イメージの根幹をなす。
1797+ We talked quite extensively about classes in the first part.
1798+ This statement will be executed, within the definition the class will
1799+ become @self@, arbitrary expressions can be written within. Class
1800+ definitions can be nested. They form the foundation of Ruby execution
1801+ image (???).
18001802
18011803h3. Method Definition
18021804
@@ -1805,20 +1807,16 @@ def m(arg)
18051807end
18061808</pre>
18071809
1808- I leave this out as I've already written about method definition.
1809-
1810- メソッドの定義は既に書いたので略。
1811- ここに入れたのは文の仲間だということを明示したかっただけだ。
1810+ I've already written about method definition and won't add more.
1811+ They also belong to statements.
18121812
18131813h3. Singleton method definition
18141814
18151815We already talked a lot about singleton methods in the first part.
18161816They do not belong to classes but to objects, in fact, they belong
1817- to singleton classes.
1818- 特異メソッドについては第一部でさんざん説明した。クラスでなくオブジェク
1819- トに所属するメソッドのことで、実は特異クラスというクラスに定義されるの
1820- だった。定義方法はメソッド名の前にレシーバを書くだけだ。パラメータ宣言
1821- でも通常のメソッドと同じ表記が全て使える。
1817+ to singleton classes. We define singleton methods by putting the
1818+ receiver in front of the method name. Parameter declaration is done
1819+ the same way like with ordinary methods.
18221820
18231821<pre class="emlist">
18241822def obj.some_method
@@ -1882,28 +1880,27 @@ a, b, c = tmp
18821880ret1, ret2 = some_method() # some_method might probably return several values
18831881</pre>
18841882
1885- Precisely speaking it is as follows.
1886-
1887- 厳密に言うと次のようになる。左辺の評価値(のオブジェクト)を`obj`と置くと、
1883+ Precisely speaking it is as follows. We will write the value of the
1884+ left hand side as @obj@.
18881885
1889- # `obj`が配列であればそれを使う
1890- # `obj`に`to_ary`メソッドが定義されていればそれで配列に変換する
1886+ # `obj` if it is an array
1887+ # if `obj` に`to_ary`メソッドが定義されていればそれで配列に変換する
18911888# `[obj]`を使う
18921889
1890+
18931891この手順に従って右辺を決定し、代入を行う。つまり右辺の評価と代入の操作は
18941892完全に独立している。
18951893
1896- まだ先がある。実は左辺・右辺とも無限にネストできる。
1897-
1894+ And it goes on, the left and right hand side can be arbitrarily nested.
18981895<pre class="emlist">
18991896a, (b, c, d) = [1, [2, 3, 4]]
19001897a, (b, (c, d)) = [1, [2, [3, 4]]]
19011898(a, b), (c, d) = [[1, 2], [3, 4]]
19021899</pre>
19031900
1904- このプログラムでは各行を実行後、` a=1 b=2 c=3 d=4`になる。
1901+ The result after each line will be the assignments @ a=1 b=2 c=3 d=4@.
19051902
1906- まだまだある。左辺にはインデックス代入や属性代入も可能。
1903+ And it goes on. The left hand side can be index or parameter assignments.
19071904
19081905<pre class="emlist">
19091906i = 0
@@ -1914,15 +1911,15 @@ p arr # [0, 2, 4]
19141911obj.attr0, obj.attr1, obj.attr2 = "a", "b", "c"
19151912</pre>
19161913
1917- メソッドのパラメータのように、`*`を使ってまとめ受けできる。
1914+ And like with method parameters, @*@ can be received.
19181915
19191916<pre class="emlist">
19201917first, *rest = 0, 1, 2, 3, 4
19211918p first # 0
19221919p rest # [1, 2, 3, 4]
19231920</pre>
19241921
1925- 一度に全部使うともう、何がなんだかわからない。
1922+ If you start using them all, you will easily get confused.
19261923
19271924h4. Block parameter and multiple assignment
19281925
@@ -1936,24 +1933,24 @@ array.each do |i|
19361933end
19371934</pre>
19381935
1939- When the block is called with a `yield`, the provided parameters are assigned to `i`.
1940- ブロックが呼ばれるたびに`yield`された引数が`i`に多重代入されているのである。
1941- ここでは左辺が変数一つだけなので多重代入に見えないのだが、二つ以上にす
1942- るとちょっと見えてくる。例えば`Hash#each`はキーと値の組に対する繰り返しな
1943- ので、普通はこのように呼ぶ。
1936+ When the block is called with a `yield`, the provided parameters are multi-assigned to `i`.
1937+ Here there's only one variable on the left hand side, so it does not look like multi assignment.
1938+ But if there are two or more variables we see what's going on. For instance @Hash#each@
1939+ provides a key and a value we usually call it like that:
19441940
19451941<pre class="emlist">
19461942hash.each do |key, value|
19471943 ....
19481944end
19491945</pre>
19501946
1951- この場合、実はキーと値の配列がハッシュから`yield`されている。
1947+ In this case an array with elements key and value are yielded
1948+ from the hash.
19521949
1953- そういうわけだから、ネストした多重代入を使って次のようなこともできる。
1950+ Hence we can also use nested multiple assignment as shown below.
19541951
19551952<pre class="emlist">
1956- # [[キー,値],インデックス]がyieldされている
1953+ # [[key,value],index] are given to yield
19571954hash.each_with_index do |(key, value), index|
19581955 ....
19591956end
@@ -2037,15 +2034,15 @@ The program reads and ignores it like a simple comment.
20372034
20382035h3. Multi-byte strings
20392036
2040- グローバル変数` $KCODE`が`" EUC"`・`" SJIS"`・`"UTF8"`のいずれかに
2041- なっているとデータの文字列の中で
2042- euc-jpやshift_jisやutf8の文字列を使うことができる。
2037+ When the global variable @ $KCODE@ is set to either @ EUC@, @ SJIS@
2038+ or @UTF8@ the strings can be encoded in EUC-JP, SHIFT-JIS or UTF-8
2039+ respectively. (?)
20432040
2044- さらに`ruby`コマンドに` -Ke`・` -Ks`・` -Ku`のどれかの
2045- オプションを付けると、
2046- コード中にすらマルチバイト文字列を使うことができるようになる。例えば
2047- 文字列リテラルや正規表現リテラル、さらには識別子にさえも使える。だから
2048- こんなことをしてもよい。
2041+ And if the option @ -Ke@, @ -Ks@ or @ -Ku@ is given to the @ruby@
2042+ command multibyte strings can be used within the Ruby code.
2043+ String literals, regular expressions and even operator names
2044+ can contain multibyte characters. Hence it is possible to do
2045+ something like this:
20492046
20502047<pre class="emlist">
20512048def 表示( arg )
@@ -2055,7 +2052,7 @@ end
20552052表示 'にほんご'
20562053</pre>
20572054
2058- しかしこういうことをやるのは全くお勧めできない。
2055+ But I really cannot recommend doing things like that.
20592056
20602057<hr>
20612058
0 commit comments