@@ -135,15 +135,13 @@ and takes everything until the ending `"`. Here documents start
135135at the line after a `<<EOS` and end at the line before the ending `EOS`.
136136
137137<pre class="emlist">
138- "<span class="ami">All characters between starting and end character are in the string</span>"
139138
140139<<EOS
141- <span class="ami"> All lines between the starting and
140+ All lines between the starting and
142141the ending line are in this
143- here document</span>
142+ here document
144143EOS
145144</pre>
146- The half toned part is a here document.
147145Here we used `EOS` as identifier but any word is fine.
148146Precisely speaking all the character matching `[a-zA-Z_0-9]` can be used.
149147
@@ -206,7 +204,7 @@ backslash notation can be used in a normal here document.
206204There does not seem to be a difference anymore to a double quote enclosed
207205here document.)
208206
209- h3. characters
207+ h3. Characters
210208
211209Ruby strings are byte strings, there are no character objects.
212210Instead there are the following expressions which return the
@@ -222,7 +220,7 @@ integers which correspond a certain character in ASCII code.
222220(Translator's note: Strings in Ruby 1.9 are not byte strings anymore,
223221they have an attached encoding. `?a` returns the string `"a"` in Ruby1.9)
224222
225- h3. Regular expressions
223+ h3. Regular Expressions
226224
227225<pre class="emlist">
228226/regexp/
@@ -361,11 +359,8 @@ arbitrary objects. The following expressions generate a table.
361359</pre>
362360
363361We explained hashes in detail in the third chapter "Names and
364- Nametables".
365-
366- ハッシュについては第3章『名前と名前表』で詳しく説明した。ハッシュ値によっ
367- て記憶スロットを分散させる高速な検索テーブルである。Ruby言語の構文と
368- してはキー・値ともに任意の式を使えるのが特徴だ。
362+ Nametables". They are fast lookup tables which allocate memory slots depending
363+ on the hash value(?). In Ruby grammar the key value can be an arbitrary expression.
369364
370365Furthermore inside a method call the braces can be omitted.
371366
@@ -381,8 +376,8 @@ button.set_geometry('x' => 80, 'y' => '240')
381376</pre>
382377
383378Of course in this case `set_geometry` must accept a hash as input.
384- 本物のキーワード引数なら言語がパラメータ変数に変換し
385- てくれるものだが、こちらはあくまで「もどき」なのでそうはいかない。
379+ Real keyword arguments will be transformed into parameter variables, though.
380+ With a passed hash it is not quite the real thing.
386381
387382h3. Ranges
388383
@@ -599,36 +594,34 @@ list = [1, 2, 3]
599594delegate(*list) # identical to delegate(1, 2, 3)
600595</pre>
601596
602-
603- このように配列を引数として分配することができる。
604- この機能を「`*`引数」と呼んでおくことにしよう。
605- ここではわかりやすいようにローカル変数経由で示したが、もちろん
606- そんな制限はない。リテラルやメソッド呼び出しなども直接置ける。
597+ In this way we can distribute an array into arguments.
598+ We call this device a `*`argument. Here we used a local variable
599+ for demonstration, but of course there is no limitation.
600+ We can also directly put a literal or a method call instead.
607601
608602<pre class="emlist">
609- m(*[1,2,3]) # これは最初から展開して書けばいいのだが……
603+ m(*[1,2,3]) # We could have written the expanded form in the first place...
610604m(*mcall())
611605</pre>
612606
613- `*`引数を普通の引数と混ぜることもできるが、
614- 必ず普通の引数より後に書かないといけない。
615- パラメータ変数との対応が一意に定まらなくなるからだ。
607+ The @*@ argument can be used together with ordinary arguments,
608+ but the @*@ argument must come last.
616609
617- 定義のときはその逆に、不定個の引数を配列としてまとめて受けることが
618- できる。パラメータ変数の前に `*`をつければいい。
610+ In the definition on the other hand we can handle the arguments in
611+ bulk when we put a `*` in front of the parameter variable.
619612
620613<pre class="emlist">
621614def some_method( *args )
622615 p args
623616end
624617
625- some_method() # []と表示される
626- some_method(0) # [0]と表示される
627- some_method(0, 1) # [0,1]と表示される
618+ some_method() # prints []
619+ some_method(0) # prints [0]
620+ some_method(0, 1) # prints [0,1]
628621</pre>
629622
630- このように、余った引数を配列にまとめてくれる。 `*`パラメータは一つしか宣
631- 言できず、またデフォルト付き引数よりも後に置かなければならない。
623+ The surplus arguments are gathered in an array. Only one `*`parameter
624+ can be declared. It must also come after the default arguments.
632625
633626<pre class="emlist">
634627def some_method0( arg, *rest )
@@ -637,9 +630,9 @@ def some_method1( arg, darg = nil, *rest )
637630end
638631</pre>
639632
640- リストの展開とまとめ受けの機能を併用すれば、メソッドの引数を別のメソッ
641- ドにそっくりそのまま引き渡すこともできる。`*`パラメータの一番便利な使
642- いかたかもしれない。
633+ If we combine list expansion and bulk reception together, the arguments
634+ of one method can be passed as a whole to another method. This might
635+ be the most practical use of the `*`parameter.
643636
644637<pre class="emlist">
645638# a method which passes its arguments to other_method
@@ -657,11 +650,12 @@ delegate(10, 20, 30) # same as other_method(10, 20, 30)
657650
658651h3. Various Method Call Expressions
659652
660- 機能が「メソッド呼び出し」というただ一つだけだからといって、その表現も
661- 一つでなければいけないという必然性はない。巷で言う
662- シンタックスシュガー(syntax sugar)である。
663- Rubyはそのシンタックスシュガーがてんこもりで、
664- パーサフェチにはたまらない。例えば次の例は全てメソッド呼び出しである。
653+ There is only one mechanism for 'method call', but there still
654+ can be several representations of the same mechanism. This is
655+ colloquially called syntactic sugar.
656+
657+ In Ruby there is a ton of it, the parser fetch becomes unbearable (?).
658+ For instance the examples below are all method calls.
665659
666660<pre class="emlist">
6676611 + 2 # 1.+(2)
@@ -673,9 +667,9 @@ obj[k] = v # obj.[]=(k,v)
673667`cvs diff abstract.rd` # Kernel.`('cvs diff abstract.rd')
674668</pre>
675669
676- 慣れるまでは信じ難いと思うが、「 `attr=`」「 `[]=`」「```」などが(本当
677- に)メソッド名なのである。メソッド定義の名前欄にも書けるし、シンボルと
678- して使うこともできる。
670+ It's hard to believe until you get used to it, but `attr=`, `[]=`, `\``
671+ are all names of methods. They can appear as names in a method definition
672+ and can also be used as symbols.
679673
680674<pre class="emlist">
681675class C
@@ -689,35 +683,38 @@ p(:[]=)
689683p(:`)
690684</pre>
691685
692- しかし甘いものなんて大嫌いだという人がよくいるのと同じで、シンタックス
693- シュガーが嫌いな人も多いようだ。たぶん、本質的な意味が一つであるものを
694- 見ためで胡麻化すのは卑怯な感じがするからだろう(みんな生真面目だね)。
686+ There are people who don't like sweets and there are people who
687+ hate syntactic sugar. Maybe because one cannot tell by the looks
688+ that it's really the same thing. It feels like a deception.
689+ (Why's everyone so serious?)
695690
696- 以下、もう少し詳しく見ていく。
691+ Let's see some more details.
697692
698- h4. 記号付き
693+ h4. Symbol Appendices
699694
700695<pre class="emlist">
701696obj.name?
702697obj.name!
703698</pre>
704699
705- 最初はギャップの小さいものから。これは単に名前の最後に`?`や`!`が付けられる
706- だけ。呼ぶときと定義するときの見ために違いがないのであまり苦労しない。
707- それぞれ「これこれこういうメソッドを定義するときに使おう」という約束事
708- はあるが、それはあくまで人間レベルの約束事であって言語規約ではない。
709- このへんは手続き名に多彩な文字が使えるLisp系言語の影響だろう。
700+ First a small thing. It's just appending a `?` or a `!`. Call and Definition
701+ do not differ, so it's not too painful. There are convention for what
702+ to use these method names, but there is no enforcement on language level.
703+ It's just a convention.
704+ These method names are probably an influence from Lisp which has a great variety
705+ of function names.
710706
711- h4. Dyadic Operators
707+ h4. Binary Operators
712708
713709<pre class="emlist">
7147101 + 2 # 1.+(2)
715711</pre>
716712
717- 二項演算子型。左辺のオブジェクトに対するメソッド呼び出しに変換される。
718- この例ならば`1`のメソッド`+`が呼ばれる。種類は以下に示すようにかなり多
719- い。`+`や`-`のような一般的な演算子から「等価」の`==`、Perl風の`<=>`な
720- んてものまで、盛り沢山だ。優先順位の高い順に並べる。
713+ Binary Operators will be converted to a method call to the object on the
714+ left hand side. Here the method `+` from the object `1` is called.
715+ As listed below there are many of them. There are the general operators
716+ `+` and `-`, also the equivalence operator `==` and the spaceship operator
717+ `<=>' as in Perl, all sorts. They are listed in order of their precedence.
721718
722719<pre class="emlist">
723720**
@@ -730,8 +727,8 @@ h4. Dyadic Operators
730727<=> == === =~
731728</pre>
732729
733- 記号一つの `&`、 `|`はメソッドだが二つになった `&&`と `||`は組み込み
734- 演算子である。Cでの使われかたを思いだすといい。
730+ The symbols `&` and `|` are methods, but the double symbols `&&` and `||`
731+ are built-in operators. Remember how it is in C.
735732
736733h4. Unary Operators
737734
@@ -757,27 +754,25 @@ obj.attr = val # attr=(val)
757754</pre>
758755
759756This is an attribute assignment statement. The above will be translated
760- into the method call `attr=`
761- 属性代入型。上記の呼び出しは`attr=`という名前のメソッド呼び出しに変換さ
762- れる。括弧を省略したメソッド呼び出しと併用すれば、以下のように
763- いかにも属性アクセスのようなふりをしたコードを書くこともできる。
757+ into the method call `attr=`. When using this together with method calls whose
758+ parantheses are omitted, we can write code which looks like attribute access.
764759
765760<pre class="emlist">
766761class C
767- def i() @i end # 実は定義は一行に書けたりする
762+ def i() @i end # We can write the definition in one line
768763 def i=(n) @i = n end
769764end
770765
771766c = C.new
772767c.i = 99
773- p c.i # 99と表示される
768+ p c.i # prints 99
774769</pre>
775770
776- しかし実はどちらもメソッド呼び出しというわけだ。
777- Delphiのget /set propertyやCLOSのスロットアクセサの仕組みと似ている。
771+ However both are method calls.
772+ They are similar to get /set property in Delphi or slot accessors in CLOS.
778773
779- ちなみに、`obj.attr(arg)=`のように引数を取りつつ代入形式、という
780- メソッドは定義できない。
774+ Besides, we cannot define a attribute assignment which takes an argument like
775+ `obj.attr(arg)=`.
781776
782777h4. Index Notation
783778
@@ -796,10 +791,11 @@ When assigning to an index the `[]=` method is used.
796791
797792h3. `super`
798793
799- メソッドを単に置き換えるのではなく、既存のメソッドの動作に少し他の
800- ことを追加したい、ということはそれなりによくあるわけだ。そこでオーバー
801- ライドしつつもスーパークラスのメソッドを呼び出す仕組みが必要になる。
802- Rubyでは`super`がソレだ。
794+ Often we don't want to replace a method, but we want to add a little
795+ bit to the behaviour of an already existing method. Here it becomes
796+ necessary to not just overwrite the method in the superclass but
797+ to also call the method in the superclass.
798+ That's what Ruby's `super` is for.
803799
804800<pre class="emlist">
805801class A
@@ -809,17 +805,18 @@ class A
809805end
810806class B < A
811807 def test
812- super # A#testを起動する
808+ super # launches A#test
813809 end
814810end
815811</pre>
816812
817- Rubyの`super`はC++やJavaとは違い、これ一語で「スーパークラスの同名のメソッ
818- ドを呼ぶ」という意味である。ちなみに`super`は予約語だ。
813+ Ruby's `super differs from the one in C++ or Java. This one here
814+ calls the method with the same name in the superclass.
815+ In other words `super` is a reserved word.
819816
820- また` super`を扱うときは「引数ゼロの`super`」と「引数を省略した`super`」の違
821- いに注意してほしい。引数を省略した `super`はメソッドのパラメータ変数を
822- そのまま渡すようになる。
817+ When using super be careful about the difference between the difference
818+ of the zero arguments `super` and the omitted arguments `super.
819+ The super with omitted arguments passes all the parameter variables.
823820
824821<pre class="emlist">
825822class A
@@ -830,11 +827,11 @@ end
830827
831828class B < A
832829 def test( a, b, c )
833- # 引数ゼロの super
834- super() # []と表示される
830+ # super with no arguments
831+ super() # shows []
835832
836- # 引数を省略した super。super (a, b, c) と同じ効果
837- super # [1, 2, 3]と表示される
833+ # super with omitted arguments. Same result as super(a, b, c)
834+ super # shows [1, 2, 3]
838835 end
839836end
840837
@@ -884,33 +881,36 @@ end
884881Here `public`, `private` and `protected are method calls without
885882parentheses. These aren't reserved words.
886883
887-
888- また`public`や`private`を引数付きで使うと特定のメソッドの可視性だけを
889- 変えることもできる。が、こちらの使いかたは仕組みが面白くないので省略。
884+ `public` and `private` can also be used with an argument to set
885+ the visibility of a particular method. But that's not really relevant.
886+ We'll leave this out.
890887
891888h4. Module functions
892889
893- モジュール`M`があったときに全く同じ内容で
890+ Given a module 'M'. If there are two methods with the exact same
891+ content
894892
895893* `M.method_name`
896- * `M#method_name`(可視性は`private`)
894+ * `M#method_name`(Visibility is `private`)
895+
897896
898- の両方が定義されている場合にそれをモジュール関数と呼ぶ。
897+ then we call this a module function.
899898
900- とは言えこの定義を聞いても存在価値がわからないと思う。使って嬉しい例を
901- 見るとわかりやすい。
899+ It is not apparent why this should be useful. But let's look
900+ at the next example which is happily used.
902901
903902<pre class="emlist">
904- Math.sin(5) # 数回使うだけならこちらのほうが楽で独立性も高い
903+ Math.sin(5) # If used for a few times this is more convenient
905904
906905include Math
907- sin(5) # 何度も使うならこちらのほうが便利
906+ sin(5) # If used more often this is more practical
908907</pre>
909908
910- 両方のメソッドが同じ内容、というところがポイントだ。`self`が違うのに一つ
911- のコードで同じ動きをするということは、インスタンス変数が非常に使いにく
912- いはずである。従ってそのようなメソッドは(`sin`のように)手続きだけを記
913- 述したメソッドである可能性が高い。だからモジュール「関数」と呼ぶのだ。
909+ It's important that both functions have the same content.
910+ With a different `self` but with the same code the behavior should
911+ still be the same. Instance variables become extremely difficult to use.
912+ Hence these methods are probably only used
913+ for procedures like `sin`. That's why they are called module functions.
914914
915915h2. Iterators
916916
0 commit comments