ruby_learner 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/README.md +17 -17
  4. data/{workshop → lib/datas}/emacs_help.org +0 -0
  5. data/lib/datas/final_history_sequential.txt +1 -0
  6. data/lib/ruby_learner/methods.rb +183 -24
  7. data/lib/ruby_learner/ruby_learner.rb +15 -7
  8. data/lib/ruby_learner/typing_practice.rb +6 -2
  9. data/lib/ruby_learner/version.rb +1 -1
  10. data/questions/sequential_check/section_1/part_1/lib/answer.rb +3 -9
  11. data/questions/sequential_check/section_1/part_1/lib/sentence.org +2 -9
  12. data/questions/sequential_check/section_1/part_1/lib/workplace.rb +1 -5
  13. data/questions/sequential_check/section_1/part_1/spec/workplace_spec.rb +6 -7
  14. data/questions/sequential_check/section_1/part_2/lib/answer.rb +4 -15
  15. data/questions/sequential_check/section_1/part_2/lib/sentence.org +2 -12
  16. data/questions/sequential_check/section_1/part_2/lib/workplace.rb +1 -5
  17. data/questions/sequential_check/section_1/part_2/spec/workplace_spec.rb +7 -9
  18. data/questions/sequential_check/section_1/part_3/lib/answer.rb +3 -0
  19. data/questions/sequential_check/section_1/part_3/lib/sentence.org +2 -0
  20. data/questions/sequential_check/section_1/part_3/lib/workplace.rb +1 -0
  21. data/questions/sequential_check/section_1/part_3/spec/spec_helper.rb +100 -0
  22. data/questions/sequential_check/section_1/part_3/spec/workplace_spec.rb +9 -0
  23. data/questions/sequential_check/section_10/part_1/lib/answer.rb +7 -0
  24. data/questions/sequential_check/section_10/part_1/lib/sentence.org +2 -0
  25. data/questions/sequential_check/section_10/part_1/lib/workplace.rb +1 -0
  26. data/questions/sequential_check/section_10/part_1/spec/spec_helper.rb +100 -0
  27. data/questions/sequential_check/section_10/part_1/spec/workplace_spec.rb +10 -0
  28. data/questions/sequential_check/section_10/part_2/lib/answer.rb +8 -0
  29. data/questions/sequential_check/section_10/part_2/lib/sentence.org +3 -0
  30. data/questions/sequential_check/section_10/part_2/lib/workplace.rb +1 -0
  31. data/questions/sequential_check/section_10/part_2/spec/spec_helper.rb +100 -0
  32. data/questions/sequential_check/section_10/part_2/spec/workplace_spec.rb +15 -0
  33. data/questions/sequential_check/section_11/part_1/lib/answer.rb +7 -0
  34. data/questions/sequential_check/section_11/part_1/lib/sentence.org +4 -0
  35. data/questions/sequential_check/section_11/part_1/lib/workplace.rb +1 -0
  36. data/questions/sequential_check/section_11/part_1/spec/spec_helper.rb +100 -0
  37. data/questions/sequential_check/section_11/part_1/spec/workplace_spec.rb +15 -0
  38. data/questions/sequential_check/section_11/part_2/lib/answer.rb +6 -0
  39. data/questions/sequential_check/section_11/part_2/lib/sentence.org +2 -0
  40. data/questions/sequential_check/section_11/part_2/lib/workplace.rb +1 -0
  41. data/questions/sequential_check/section_11/part_2/spec/spec_helper.rb +100 -0
  42. data/questions/sequential_check/section_11/part_2/spec/workplace_spec.rb +13 -0
  43. data/questions/sequential_check/section_2/part_1/lib/answer.rb +8 -0
  44. data/questions/sequential_check/section_2/part_1/lib/sentence.org +2 -0
  45. data/questions/sequential_check/section_2/part_1/lib/workplace.rb +1 -0
  46. data/questions/sequential_check/section_2/part_1/spec/spec_helper.rb +100 -0
  47. data/questions/sequential_check/section_2/part_1/spec/workplace_spec.rb +14 -0
  48. data/questions/sequential_check/section_2/part_2/lib/answer.rb +14 -0
  49. data/questions/sequential_check/section_2/part_2/lib/sentence.org +2 -0
  50. data/questions/sequential_check/section_2/part_2/lib/workplace.rb +1 -0
  51. data/questions/sequential_check/section_2/part_2/spec/spec_helper.rb +100 -0
  52. data/questions/sequential_check/section_2/part_2/spec/workplace_spec.rb +14 -0
  53. data/questions/sequential_check/section_3/part_1/lib/answer.rb +11 -0
  54. data/questions/sequential_check/section_3/part_1/lib/sentence.org +2 -0
  55. data/questions/sequential_check/section_3/part_1/lib/workplace.rb +1 -0
  56. data/questions/sequential_check/section_3/part_1/spec/spec_helper.rb +100 -0
  57. data/questions/sequential_check/section_3/part_1/spec/workplace_spec.rb +15 -0
  58. data/questions/sequential_check/section_4/part_1/lib/answer.rb +9 -0
  59. data/questions/sequential_check/section_4/part_1/lib/sentence.org +2 -0
  60. data/questions/sequential_check/section_4/part_1/lib/workplace.rb +2 -0
  61. data/questions/sequential_check/section_4/part_1/spec/spec_helper.rb +100 -0
  62. data/questions/sequential_check/section_4/part_1/spec/workplace_spec.rb +14 -0
  63. data/questions/sequential_check/section_5/part_1/lib/answer.rb +8 -0
  64. data/questions/sequential_check/section_5/part_1/lib/sentence.org +2 -0
  65. data/questions/sequential_check/section_5/part_1/lib/workplace.rb +1 -0
  66. data/questions/sequential_check/section_5/part_1/spec/spec_helper.rb +100 -0
  67. data/questions/sequential_check/section_5/part_1/spec/workplace_spec.rb +14 -0
  68. data/questions/sequential_check/section_5/part_2/lib/answer.rb +5 -0
  69. data/questions/sequential_check/section_5/part_2/lib/sentence.org +2 -0
  70. data/questions/sequential_check/section_5/part_2/lib/workplace.rb +1 -0
  71. data/questions/sequential_check/section_5/part_2/spec/spec_helper.rb +100 -0
  72. data/questions/sequential_check/section_5/part_2/spec/workplace_spec.rb +9 -0
  73. data/questions/sequential_check/section_6/part_1/lib/answer.rb +5 -0
  74. data/questions/sequential_check/section_6/part_1/lib/sentence.org +2 -0
  75. data/questions/sequential_check/section_6/part_1/lib/workplace.rb +1 -0
  76. data/questions/sequential_check/section_6/part_1/spec/spec_helper.rb +100 -0
  77. data/questions/sequential_check/section_6/part_1/spec/workplace_spec.rb +14 -0
  78. data/questions/sequential_check/section_6/part_2/lib/answer.rb +7 -0
  79. data/questions/sequential_check/section_6/part_2/lib/sentence.org +3 -0
  80. data/questions/sequential_check/section_6/part_2/lib/workplace.rb +1 -0
  81. data/questions/sequential_check/section_6/part_2/spec/spec_helper.rb +100 -0
  82. data/questions/sequential_check/section_6/part_2/spec/workplace_spec.rb +14 -0
  83. data/questions/sequential_check/section_6/part_3/lib/answer.rb +7 -0
  84. data/questions/sequential_check/section_6/part_3/lib/sentence.org +3 -0
  85. data/questions/sequential_check/section_6/part_3/lib/workplace.rb +1 -0
  86. data/questions/sequential_check/section_6/part_3/spec/spec_helper.rb +100 -0
  87. data/questions/sequential_check/section_6/part_3/spec/workplace_spec.rb +9 -0
  88. data/questions/sequential_check/section_6/part_4/lib/answer.rb +9 -0
  89. data/questions/sequential_check/section_6/part_4/lib/sentence.org +3 -0
  90. data/questions/sequential_check/section_6/part_4/lib/workplace.rb +1 -0
  91. data/questions/sequential_check/section_6/part_4/spec/spec_helper.rb +100 -0
  92. data/questions/sequential_check/section_6/part_4/spec/workplace_spec.rb +9 -0
  93. data/questions/sequential_check/section_7/part_1/lib/answer.rb +5 -0
  94. data/questions/sequential_check/section_7/part_1/lib/sentence.org +3 -0
  95. data/questions/sequential_check/section_7/part_1/lib/workplace.rb +1 -0
  96. data/questions/sequential_check/section_7/part_1/spec/spec_helper.rb +100 -0
  97. data/questions/sequential_check/section_7/part_1/spec/workplace_spec.rb +14 -0
  98. data/questions/sequential_check/section_7/part_2/lib/answer.rb +9 -0
  99. data/questions/sequential_check/section_7/part_2/lib/sentence.org +2 -0
  100. data/questions/sequential_check/section_7/part_2/lib/workplace.rb +1 -0
  101. data/questions/sequential_check/section_7/part_2/spec/spec_helper.rb +100 -0
  102. data/questions/sequential_check/section_7/part_2/spec/workplace_spec.rb +10 -0
  103. data/questions/sequential_check/section_8/part_1/lib/answer.rb +9 -0
  104. data/questions/sequential_check/section_8/part_1/lib/sentence.org +2 -0
  105. data/questions/sequential_check/section_8/part_1/lib/workplace.rb +1 -0
  106. data/questions/sequential_check/section_8/part_1/spec/spec_helper.rb +100 -0
  107. data/questions/sequential_check/section_8/part_1/spec/workplace_spec.rb +15 -0
  108. data/questions/sequential_check/section_9/part_1/lib/answer.rb +5 -0
  109. data/questions/sequential_check/section_9/part_1/lib/sentence.org +2 -0
  110. data/questions/sequential_check/section_9/part_1/lib/workplace.rb +1 -0
  111. data/questions/sequential_check/section_9/part_1/spec/spec_helper.rb +100 -0
  112. data/questions/sequential_check/section_9/part_1/spec/workplace_spec.rb +10 -0
  113. data/questions/sequential_check/section_9/part_2/lib/answer.rb +7 -0
  114. data/questions/sequential_check/section_9/part_2/lib/sentence.org +2 -0
  115. data/questions/sequential_check/section_9/part_2/lib/workplace.rb +1 -0
  116. data/questions/sequential_check/section_9/part_2/spec/spec_helper.rb +100 -0
  117. data/questions/sequential_check/section_9/part_2/spec/workplace_spec.rb +10 -0
  118. data/questions/sequential_check/section_9/part_3/lib/answer.rb +12 -0
  119. data/questions/sequential_check/section_9/part_3/lib/sentence.org +2 -0
  120. data/questions/sequential_check/section_9/part_3/lib/workplace.rb +1 -0
  121. data/questions/sequential_check/section_9/part_3/spec/spec_helper.rb +100 -0
  122. data/questions/sequential_check/section_9/part_3/spec/workplace_spec.rb +10 -0
  123. data/takahashi/docs/README.org +9 -0
  124. data/takahashi/docs/README.org~ +139 -0
  125. data/takahashi/docs/drill.html +189 -135
  126. data/takahashi/docs/drill.html~ +171 -187
  127. data/takahashi/docs/drill.org +163 -120
  128. data/takahashi/sample_prog/answer/10_2.rb +6 -0
  129. data/takahashi/sample_prog/answer/8_1.rb +9 -0
  130. data/takahashi/sample_prog/question/10_1.rb +2 -0
  131. data/takahashi/sample_prog/question/10_2.rb +3 -0
  132. data/takahashi/sample_prog/question/11_1.rb +4 -0
  133. data/takahashi/sample_prog/question/11_2.rb +2 -0
  134. data/takahashi/sample_prog/question/1_1.rb +2 -0
  135. data/takahashi/sample_prog/question/1_2.rb +2 -0
  136. data/takahashi/sample_prog/question/1_3.rb +2 -0
  137. data/takahashi/sample_prog/question/2_1.rb +2 -0
  138. data/takahashi/sample_prog/question/2_2.rb +2 -0
  139. data/takahashi/sample_prog/question/3_1.rb +2 -0
  140. data/takahashi/sample_prog/question/4_1.rb +2 -0
  141. data/takahashi/sample_prog/question/5_1.rb +2 -0
  142. data/takahashi/sample_prog/question/5_2.rb +2 -0
  143. data/takahashi/sample_prog/question/6_1.rb +2 -0
  144. data/takahashi/sample_prog/question/6_2.rb +3 -0
  145. data/takahashi/sample_prog/question/6_3.rb +3 -0
  146. data/takahashi/sample_prog/question/6_4.rb +3 -0
  147. data/takahashi/sample_prog/question/7_1.rb +3 -0
  148. data/takahashi/sample_prog/question/7_2.rb +2 -0
  149. data/takahashi/sample_prog/question/8_1.rb +2 -0
  150. data/takahashi/sample_prog/question/9_1.rb +2 -0
  151. data/takahashi/sample_prog/question/9_2.rb +2 -0
  152. data/takahashi/sample_prog/question/9_3.rb +2 -0
  153. data/workshop/emacs.d/#init# +1 -0
  154. data/workshop/emacs.d/init.el +8 -8
  155. data/workshop/emacs.d/ruby_learner_init.el +8 -8
  156. data/workshop/lib/for-def-read.rb +3 -0
  157. data/workshop/lib/for-read.txt +5 -0
  158. metadata +138 -7
  159. data/lib/ruby_learner/h.rb +0 -14
  160. data/lib/ruby_learner/random_h.rb +0 -16
  161. data/lib/ruby_learner/sequential_h.rb +0 -15
  162. data/workshop/training_data.txt +0 -3
@@ -4,7 +4,7 @@
4
4
  <html xmlns="http://www.w3.org/1999/xhtml" lang="jp" xml:lang="jp">
5
5
  <head>
6
6
  <title>はじめてのRuby</title>
7
- <!-- 2018-08-04 04:56 -->
7
+ <!-- 2018-08-09 17:09 -->
8
8
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
9
9
  <meta name="generator" content="Org-mode" />
10
10
  <meta name="author" content="Shun Takahashi" />
@@ -198,46 +198,45 @@ for the JavaScript code in this tag.
198
198
  <li><a href="#sec-1-4">1.4. kiritsubo.rb</a></li>
199
199
  </ul>
200
200
  </li>
201
- <li><a href="#sec-2">2. 変数</a>
201
+ <li><a href="#sec-2">2. コマンドラインからのデータの入力</a>
202
202
  <ul>
203
- <li><a href="#sec-2-1">2.1. area_volume.rb</a></li>
203
+ <li><a href="#sec-2-1">2.1. print_argv.rb</a></li>
204
+ <li><a href="#sec-2-2">2.2. arg_arith.rb</a></li>
204
205
  </ul>
205
206
  </li>
206
- <li><a href="#sec-3">3. 条件判断</a>
207
+ <li><a href="#sec-3">3. 変数</a>
207
208
  <ul>
208
- <li><a href="#sec-3-1">3.1. greater_smaller.rb</a></li>
209
- <li><a href="#sec-3-2">3.2. greater_smaller_else.rb</a></li>
209
+ <li><a href="#sec-3-1">3.1. area_volume.rb</a></li>
210
210
  </ul>
211
211
  </li>
212
- <li><a href="#sec-4">4. 繰り返し</a>
212
+ <li><a href="#sec-4">4. 条件判断</a>
213
213
  <ul>
214
- <li><a href="#sec-4-1">4.1. 1_to_n.rb</a></li>
215
- <li><a href="#sec-4-2">4.2. five_times.rb</a></li>
214
+ <li><a href="#sec-4-1">4.1. greater_smaller_else.rb</a></li>
216
215
  </ul>
217
216
  </li>
218
- <li><a href="#sec-5">5. 配列</a>
217
+ <li><a href="#sec-5">5. 繰り返し</a>
219
218
  <ul>
220
- <li><a href="#sec-5-1">5.1. 配列からオブジェクトを取り出す</a></li>
221
- <li><a href="#sec-5-2">5.2. 配列にオブジェクトを格納する</a></li>
222
- <li><a href="#sec-5-3">5.3. 配列の大きさ</a></li>
223
- <li><a href="#sec-5-4">5.4. 配列と繰り返し</a></li>
219
+ <li><a href="#sec-5-1">5.1. 1_to_n.rb</a></li>
220
+ <li><a href="#sec-5-2">5.2. five_times.rb</a></li>
224
221
  </ul>
225
222
  </li>
226
- <li><a href="#sec-6">6. ハッシュ</a>
223
+ <li><a href="#sec-6">6. 配列</a>
227
224
  <ul>
228
- <li><a href="#sec-6-1">6.1. シンボル</a></li>
229
- <li><a href="#sec-6-2">6.2. ハッシュの操作</a></li>
225
+ <li><a href="#sec-6-1">6.1. 配列からオブジェクトを取り出す</a></li>
226
+ <li><a href="#sec-6-2">6.2. 配列にオブジェクトを格納する</a></li>
227
+ <li><a href="#sec-6-3">6.3. 配列の大きさ</a></li>
228
+ <li><a href="#sec-6-4">6.4. 配列と繰り返し</a></li>
230
229
  </ul>
231
230
  </li>
232
- <li><a href="#sec-7">7. 正規表現</a>
231
+ <li><a href="#sec-7">7. ハッシュ</a>
233
232
  <ul>
234
- <li><a href="#sec-7-1">7.1. パターンとマッチング</a></li>
233
+ <li><a href="#sec-7-1">7.1. シンボル</a></li>
234
+ <li><a href="#sec-7-2">7.2. ハッシュの操作</a></li>
235
235
  </ul>
236
236
  </li>
237
- <li><a href="#sec-8">8. コマンドラインからのデータの入力</a>
237
+ <li><a href="#sec-8">8. 正規表現</a>
238
238
  <ul>
239
- <li><a href="#sec-8-1">8.1. List3.1 print_argv.rb</a></li>
240
- <li><a href="#sec-8-2">8.2. List3.3 arg_arith.rb</a></li>
239
+ <li><a href="#sec-8-1">8.1. パターンとマッチング</a></li>
241
240
  </ul>
242
241
  </li>
243
242
  <li><a href="#sec-9">9. ファイルからの読み込み</a>
@@ -254,7 +253,8 @@ for the JavaScript code in this tag.
254
253
  </li>
255
254
  <li><a href="#sec-11">11. 別のファイルを取り込む</a>
256
255
  <ul>
257
- <li><a href="#sec-11-1">11.1. Rubyの標準ライブラリ</a></li>
256
+ <li><a href="#sec-11-1">11.1. ディレクトリ内のファイルの取り込み</a></li>
257
+ <li><a href="#sec-11-2">11.2. Rubyの標準ライブラリ</a></li>
258
258
  </ul>
259
259
  </li>
260
260
  </ul>
@@ -274,11 +274,12 @@ for the JavaScript code in this tag.
274
274
 
275
275
  <div class="org-src-container">
276
276
 
277
- <pre class="src src-ruby">print('Hello, Ruby.\n')
277
+ <pre class="src src-ruby">print 'Hello, Ruby.\n'
278
278
  </pre>
279
279
  </div>
280
280
 
281
281
  <pre class="example">
282
+ &gt; answer.rb
282
283
  Hello, Ruby.
283
284
  </pre>
284
285
  </div>
@@ -293,13 +294,13 @@ Hello, Ruby.
293
294
 
294
295
  <div class="org-src-container">
295
296
 
296
- <pre class="src src-ruby">print("Hello, \"Ruby\".\n")
297
+ <pre class="src src-ruby">print Hello, \"Ruby\".\n"
297
298
  </pre>
298
299
  </div>
299
300
 
300
301
  <pre class="example">
301
- &gt; helloruby_2.rb
302
- Hello,"Ruby".
302
+ &gt; answer.rb
303
+ Hello, "Ruby".
303
304
  </pre>
304
305
  </div>
305
306
  </div>
@@ -316,11 +317,14 @@ Hello,"Ruby".
316
317
  <pre class="src src-ruby">p "Hello,\n\tRuby."
317
318
  </pre>
318
319
  </div>
320
+
321
+ <pre class="example">
322
+ &gt; answer.rb
323
+ "Hello,\n\tRuby."
324
+ </pre>
319
325
  </div>
320
326
  </div>
321
327
 
322
-
323
-
324
328
  <div id="outline-container-sec-1-4" class="outline-3">
325
329
  <h3 id="sec-1-4"><span class="section-number-3">1.4</span> kiritsubo.rb</h3>
326
330
  <div class="outline-text-3" id="text-1-4">
@@ -329,76 +333,112 @@ Hello,"Ruby".
329
333
  </div>
330
334
 
331
335
  <div id="outline-container-sec-2" class="outline-2">
332
- <h2 id="sec-2"><span class="section-number-2">2</span> 変数</h2>
336
+ <h2 id="sec-2"><span class="section-number-2">2</span> コマンドラインからのデータの入力</h2>
333
337
  <div class="outline-text-2" id="text-2">
334
338
  </div><div id="outline-container-sec-2-1" class="outline-3">
335
- <h3 id="sec-2-1"><span class="section-number-3">2.1</span> area_volume.rb</h3>
339
+ <h3 id="sec-2-1"><span class="section-number-3">2.1</span> print_argv.rb</h3>
336
340
  <div class="outline-text-3" id="text-2-1">
337
341
  <p>
338
- 3つの数値x、y、zを受け取り、縦x、横y、高さzの直方体の表面積と体積を求めるプログラム
342
+ コマンドラインから引数を5つ入力として受け取り、出力するプログラム
339
343
  </p>
340
344
 
341
345
  <div class="org-src-container">
342
346
 
343
- <pre class="src src-ruby">x = ARGV[0].to_i
344
- y = ARGV[1].to_i
345
- z = ARGV[2].to_i
347
+ <pre class="src src-ruby">puts ARGV[0]
348
+ puts ARGV[1]
349
+ puts ARGV[2]
350
+ puts ARGV[3]
351
+ puts ARGV[4]
352
+ </pre>
353
+ </div>
346
354
 
347
- area = (x*y + y*z + z*x) * 2
348
- volume = x * y * z
355
+ <pre class="example">
356
+ &gt; ruby answer.rb 1st 2nd 3rd 4th 5th
357
+ 1st
358
+ 2nd
359
+ 3rd
360
+ 4th
361
+ 5th
362
+ </pre>
363
+ </div>
364
+ </div>
349
365
 
350
- print "表面積=", area, "\n"
351
- print "体積=" volume, "\n"
366
+ <div id="outline-container-sec-2-2" class="outline-3">
367
+ <h3 id="sec-2-2"><span class="section-number-3">2.2</span> arg_arith.rb</h3>
368
+ <div class="outline-text-3" id="text-2-2">
369
+ <p>
370
+ コマンドラインから数値を2つ受け取り、和、差、積、商を表示するプログラム
371
+ </p>
372
+
373
+ <div class="org-src-container">
374
+
375
+ <pre class="src src-ruby">num0 = ARGV[0].to_i
376
+ num1 = ARGV[1].to_i
377
+
378
+ sum = num0 + num1
379
+ dif = num0 - num1
380
+ pro = num0 * num1
381
+ quo = num0 / num1
382
+
383
+ puts sum
384
+ puts dif
385
+ puts pro
386
+ puts quo
352
387
  </pre>
353
388
  </div>
354
389
 
355
390
  <pre class="example">
356
- &gt; ruby area_volume.rb 10 20 30
357
- 表面積=2200
358
- 体積=6000
391
+ &gt; ruby answer.rb 5 3
392
+ 8
393
+ 2
394
+ 15
395
+ 1
359
396
  </pre>
360
397
  </div>
361
398
  </div>
362
399
  </div>
363
400
 
364
401
  <div id="outline-container-sec-3" class="outline-2">
365
- <h2 id="sec-3"><span class="section-number-2">3</span> 条件判断</h2>
402
+ <h2 id="sec-3"><span class="section-number-2">3</span> 変数</h2>
366
403
  <div class="outline-text-2" id="text-3">
367
404
  </div><div id="outline-container-sec-3-1" class="outline-3">
368
- <h3 id="sec-3-1"><span class="section-number-3">3.1</span> greater_smaller.rb</h3>
405
+ <h3 id="sec-3-1"><span class="section-number-3">3.1</span> area_volume.rb</h3>
369
406
  <div class="outline-text-3" id="text-3-1">
370
407
  <p>
371
- 数値を1つ引数として受け取り、それが10以上ならば「greater」、9以下ならば「smaller」と出力するプログラム
408
+ 3つの数値x、y、zを受け取り、縦x、横y、高さzの直方体の表面積と体積を求めるプログラム
372
409
  </p>
373
410
 
374
411
  <div class="org-src-container">
375
412
 
376
- <pre class="src src-ruby">a = ARGV[0].to_i
413
+ <pre class="src src-ruby">x = ARGV[0].to_i
414
+ y = ARGV[1].to_i
415
+ z = ARGV[2].to_i
377
416
 
378
- if a &gt;= 10
379
- print "greater\n"
380
- end
381
- if a &lt;= 9
382
- print "smaller\n"
383
- end
417
+ area = (x * y + y * z + z * x) * 2
418
+ volume = x * y * z
419
+
420
+ print '表面積=', area, "\n"
421
+ print '体積=' volume, "\n"
384
422
  </pre>
385
423
  </div>
386
424
 
387
425
  <pre class="example">
388
- &gt;ruby greater_smaller_else.rb 20
389
- greater
390
-
391
- &gt;ruby greater_smaller_else.rb 5
392
- smaller
426
+ &gt; ruby answer.rb 10 20 30
427
+ 表面積=2200
428
+ 体積=6000
393
429
  </pre>
394
430
  </div>
395
431
  </div>
432
+ </div>
396
433
 
397
- <div id="outline-container-sec-3-2" class="outline-3">
398
- <h3 id="sec-3-2"><span class="section-number-3">3.2</span> greater_smaller_else.rb</h3>
399
- <div class="outline-text-3" id="text-3-2">
434
+ <div id="outline-container-sec-4" class="outline-2">
435
+ <h2 id="sec-4"><span class="section-number-2">4</span> 条件判断</h2>
436
+ <div class="outline-text-2" id="text-4">
437
+ </div><div id="outline-container-sec-4-1" class="outline-3">
438
+ <h3 id="sec-4-1"><span class="section-number-3">4.1</span> greater_smaller_else.rb</h3>
439
+ <div class="outline-text-3" id="text-4-1">
400
440
  <p>
401
- List1.6のプログラムと同じ処理を、elseを用いて実行するプログラム
441
+ 数値を1つ引数として受け取り、それが10より大きければ「greater」小さければ「smaller」と表示するプログラム
402
442
  </p>
403
443
 
404
444
  <div class="org-src-container">
@@ -409,26 +449,27 @@ if a &gt;= 10
409
449
  print "greater\n"
410
450
  else
411
451
  print "smaller\n"
452
+ end
412
453
  </pre>
413
454
  </div>
414
455
 
415
456
  <pre class="example">
416
- &gt;ruby greater_smaller_else.rb 20
457
+ &gt;ruby answer.rb 20
417
458
  greater
418
459
 
419
- &gt;ruby greater_smaller_else.rb 5
460
+ &gt;ruby answer.rb 5
420
461
  smaller
421
462
  </pre>
422
463
  </div>
423
464
  </div>
424
465
  </div>
425
466
 
426
- <div id="outline-container-sec-4" class="outline-2">
427
- <h2 id="sec-4"><span class="section-number-2">4</span> 繰り返し</h2>
428
- <div class="outline-text-2" id="text-4">
429
- </div><div id="outline-container-sec-4-1" class="outline-3">
430
- <h3 id="sec-4-1"><span class="section-number-3">4.1</span> 1_to_n.rb</h3>
431
- <div class="outline-text-3" id="text-4-1">
467
+ <div id="outline-container-sec-5" class="outline-2">
468
+ <h2 id="sec-5"><span class="section-number-2">5</span> 繰り返し</h2>
469
+ <div class="outline-text-2" id="text-5">
470
+ </div><div id="outline-container-sec-5-1" class="outline-3">
471
+ <h3 id="sec-5-1"><span class="section-number-3">5.1</span> 1_to_n.rb</h3>
472
+ <div class="outline-text-3" id="text-5-1">
432
473
  <p>
433
474
  入力された1つの数値nを引数として受け取り、1からnまでの数を順番に表示するプログラムを作成せよ
434
475
  </p>
@@ -439,13 +480,13 @@ smaller
439
480
  i = 1
440
481
  while i &lt;= n
441
482
  print i, "\n"
442
- i = i + 1
483
+ i += 1
443
484
  end
444
485
  </pre>
445
486
  </div>
446
487
 
447
488
  <pre class="example">
448
- &gt; ruby 1_to_n.rb 5
489
+ &gt; ruby answer.rb 5
449
490
  1
450
491
  2
451
492
  3
@@ -455,10 +496,9 @@ end
455
496
  </div>
456
497
  </div>
457
498
 
458
-
459
- <div id="outline-container-sec-4-2" class="outline-3">
460
- <h3 id="sec-4-2"><span class="section-number-3">4.2</span> five_times.rb</h3>
461
- <div class="outline-text-3" id="text-4-2">
499
+ <div id="outline-container-sec-5-2" class="outline-3">
500
+ <h3 id="sec-5-2"><span class="section-number-3">5.2</span> five_times.rb</h3>
501
+ <div class="outline-text-3" id="text-5-2">
462
502
  <p>
463
503
  「All work and no play makes Jack a dull boy.」と5行表示するプログラム
464
504
  </p>
@@ -466,56 +506,66 @@ end
466
506
  <div class="org-src-container">
467
507
 
468
508
  <pre class="src src-ruby">5.times do
469
- print "All work and no play makes Jack a dull boy."
509
+ print "All work and no play makes Jack a dull boy.\n"
470
510
  end
471
511
  </pre>
472
512
  </div>
513
+
514
+ <pre class="example">
515
+ &gt; answer.rb
516
+ All work and no play makes Jack a dull boy.
517
+ All work and no play makes Jack a dull boy.
518
+ All work and no play makes Jack a dull boy.
519
+ All work and no play makes Jack a dull boy.
520
+ All work and no play makes Jack a dull boy.
521
+ </pre>
473
522
  </div>
474
523
  </div>
475
524
  </div>
476
525
 
477
526
 
478
-
479
-
480
- <div id="outline-container-sec-5" class="outline-2">
481
- <h2 id="sec-5"><span class="section-number-2">5</span> 配列</h2>
482
- <div class="outline-text-2" id="text-5">
483
- </div><div id="outline-container-sec-5-1" class="outline-3">
484
- <h3 id="sec-5-1"><span class="section-number-3">5.1</span> 配列からオブジェクトを取り出す</h3>
485
- <div class="outline-text-3" id="text-5-1">
527
+ <div id="outline-container-sec-6" class="outline-2">
528
+ <h2 id="sec-6"><span class="section-number-2">6</span> 配列</h2>
529
+ <div class="outline-text-2" id="text-6">
530
+ </div><div id="outline-container-sec-6-1" class="outline-3">
531
+ <h3 id="sec-6-1"><span class="section-number-3">6.1</span> 配列からオブジェクトを取り出す</h3>
532
+ <div class="outline-text-3" id="text-6-1">
486
533
  <p>
487
- 配列のn番目の要素を取り出し、表示するプログラム
534
+ 配列のn番目の要素を取り出し、表示するプログラム.ただし、配列には数値が入るものとする。
488
535
  </p>
489
536
 
490
537
  <div class="org-src-container">
491
538
 
492
- <pre class="src src-ruby">names = ["小林", "林", "高野", "森岡"]
539
+ <pre class="src src-ruby">nums = [3, 1, 4, 1, 5]
493
540
 
494
- print names[ARGV[0]]
541
+ print nums[ARGV[0].to_i]
495
542
  </pre>
496
543
  </div>
497
544
 
498
545
  <div class="org-src-container">
499
546
 
500
- <pre class="src src-ruby">&gt;ruby answer.rb 0
501
- 小林
547
+ <pre class="src src-ruby">&gt; ruby answer.rb 0
548
+ 3
549
+
550
+ &gt; ruby answer.rb 3
551
+ 1
502
552
  </pre>
503
553
  </div>
504
554
  </div>
505
555
  </div>
506
556
 
507
- <div id="outline-container-sec-5-2" class="outline-3">
508
- <h3 id="sec-5-2"><span class="section-number-3">5.2</span> 配列にオブジェクトを格納する</h3>
509
- <div class="outline-text-3" id="text-5-2">
557
+ <div id="outline-container-sec-6-2" class="outline-3">
558
+ <h3 id="sec-6-2"><span class="section-number-3">6.2</span> 配列にオブジェクトを格納する</h3>
559
+ <div class="outline-text-3" id="text-6-2">
510
560
  <p>
511
561
  配列の先頭の要素をコマンドラインに入力した要素に変更するプログラム
512
562
  </p>
513
563
 
514
564
  <div class="org-src-container">
515
565
 
516
- <pre class="src src-ruby">nums = [1, 2, 3]
566
+ <pre class="src src-ruby">nums = [3, 1, 4, 1, 5]
517
567
 
518
- nums[0] = ARGV[0]
568
+ nums[0] = ARGV[0].to_i
519
569
 
520
570
  print nums
521
571
  </pre>
@@ -524,14 +574,14 @@ print nums
524
574
 
525
575
  <pre class="example">
526
576
  &gt; ruby answer.rb 5
527
- [5, 2, 3]
577
+ [5, 1, 4, 1, 5]
528
578
  </pre>
529
579
  </div>
530
580
  </div>
531
581
 
532
- <div id="outline-container-sec-5-3" class="outline-3">
533
- <h3 id="sec-5-3"><span class="section-number-3">5.3</span> 配列の大きさ</h3>
534
- <div class="outline-text-3" id="text-5-3">
582
+ <div id="outline-container-sec-6-3" class="outline-3">
583
+ <h3 id="sec-6-3"><span class="section-number-3">6.3</span> 配列の大きさ</h3>
584
+ <div class="outline-text-3" id="text-6-3">
535
585
  <p>
536
586
  配列を表示し、その配列の大きさも表示するプログラムを作成せよ
537
587
  </p>
@@ -548,10 +598,9 @@ print names.size
548
598
  </div>
549
599
  </div>
550
600
 
551
-
552
- <div id="outline-container-sec-5-4" class="outline-3">
553
- <h3 id="sec-5-4"><span class="section-number-3">5.4</span> 配列と繰り返し</h3>
554
- <div class="outline-text-3" id="text-5-4">
601
+ <div id="outline-container-sec-6-4" class="outline-3">
602
+ <h3 id="sec-6-4"><span class="section-number-3">6.4</span> 配列と繰り返し</h3>
603
+ <div class="outline-text-3" id="text-6-4">
555
604
  <p>
556
605
  配列全体を表示してから、配列の要素を順に表示するプログラム
557
606
  </p>
@@ -580,12 +629,12 @@ end
580
629
  </div>
581
630
  </div>
582
631
 
583
- <div id="outline-container-sec-6" class="outline-2">
584
- <h2 id="sec-6"><span class="section-number-2">6</span> ハッシュ</h2>
585
- <div class="outline-text-2" id="text-6">
586
- </div><div id="outline-container-sec-6-1" class="outline-3">
587
- <h3 id="sec-6-1"><span class="section-number-3">6.1</span> シンボル</h3>
588
- <div class="outline-text-3" id="text-6-1">
632
+ <div id="outline-container-sec-7" class="outline-2">
633
+ <h2 id="sec-7"><span class="section-number-2">7</span> ハッシュ</h2>
634
+ <div class="outline-text-2" id="text-7">
635
+ </div><div id="outline-container-sec-7-1" class="outline-3">
636
+ <h3 id="sec-7-1"><span class="section-number-3">7.1</span> シンボル</h3>
637
+ <div class="outline-text-3" id="text-7-1">
589
638
  <p>
590
639
  コマンドラインから文字列を受け取り、シンボルに変換して表示するプログラム
591
640
  </p>
@@ -605,9 +654,9 @@ p n.to_sym
605
654
  </div>
606
655
  </div>
607
656
 
608
- <div id="outline-container-sec-6-2" class="outline-3">
609
- <h3 id="sec-6-2"><span class="section-number-3">6.2</span> ハッシュの操作</h3>
610
- <div class="outline-text-3" id="text-6-2">
657
+ <div id="outline-container-sec-7-2" class="outline-3">
658
+ <h3 id="sec-7-2"><span class="section-number-3">7.2</span> ハッシュの操作</h3>
659
+ <div class="outline-text-3" id="text-7-2">
611
660
  <p>
612
661
  :name, :furiganaというそれぞれのキーに"高橋", "タカハシ"というオブジェクトが格納されているハッシュを表示、さらに:telというキーに"000-1234-5678"を格納して再度表示するプログラム
613
662
  </p>
@@ -633,82 +682,16 @@ puts address
633
682
  </div>
634
683
  </div>
635
684
 
636
-
637
- <div id="outline-container-sec-7" class="outline-2">
638
- <h2 id="sec-7"><span class="section-number-2">7</span> 正規表現</h2>
639
- <div class="outline-text-2" id="text-7">
640
- </div><div id="outline-container-sec-7-1" class="outline-3">
641
- <h3 id="sec-7-1"><span class="section-number-3">7.1</span> パターンとマッチング</h3>
642
- <div class="outline-text-3" id="text-7-1">
643
- <div class="org-src-container">
644
-
645
- <pre class="src src-ruby"></pre>
646
- </div>
647
- </div>
648
- </div>
649
- </div>
650
-
651
685
  <div id="outline-container-sec-8" class="outline-2">
652
- <h2 id="sec-8"><span class="section-number-2">8</span> コマンドラインからのデータの入力</h2>
686
+ <h2 id="sec-8"><span class="section-number-2">8</span> 正規表現</h2>
653
687
  <div class="outline-text-2" id="text-8">
654
688
  </div><div id="outline-container-sec-8-1" class="outline-3">
655
- <h3 id="sec-8-1"><span class="section-number-3">8.1</span> List3.1 print_argv.rb</h3>
689
+ <h3 id="sec-8-1"><span class="section-number-3">8.1</span> パターンとマッチング</h3>
656
690
  <div class="outline-text-3" id="text-8-1">
657
- <p>
658
- コマンドラインから引数を5つ入力として受け取り、出力するプログラム
659
- </p>
660
-
661
- <div class="org-src-container">
662
-
663
- <pre class="src src-ruby"># List3.1 print_argv.rb
664
- puts "最初の引数: #{ARGV[0]}"
665
- puts "2番目の引数: #{ARGV[1]}"
666
- puts "3番目の引数: #{ARGV[2]}"
667
- puts "4番目の引数: #{ARGV[3]}"
668
- puts "5番目の引数: #{ARGV[4]}"
669
- </pre>
670
- </div>
671
-
672
- <pre class="example">
673
- 実行例
674
- &gt; ruby print_argv.rb 1st 2nd 3rd 4th 5th
675
- 最初の引数: 1st
676
- 2番目の引数: 2nd
677
- 3番目の引数: 3rd
678
- 4番目の引数: 4th
679
- 5番目の引数: 5th
680
- </pre>
681
- </div>
682
- </div>
683
-
684
-
685
-
686
- <div id="outline-container-sec-8-2" class="outline-3">
687
- <h3 id="sec-8-2"><span class="section-number-3">8.2</span> List3.3 arg_arith.rb</h3>
688
- <div class="outline-text-3" id="text-8-2">
689
- <p>
690
- コマンドラインから数値を2つ受け取り、和、差、積、商を表示するプログラム
691
- </p>
692
-
693
691
  <div class="org-src-container">
694
692
 
695
- <pre class="src src-ruby">num0 = ARGV[0].to_i
696
- num1 = ARGV[1].to_i
697
-
698
- puts "#{num0 + num1}"
699
- puts "#{num0 - num1}"
700
- puts "#{num0 * num1}"
701
- puts "#{num0 / num1}"
702
- </pre>
693
+ <pre class="src src-ruby"></pre>
703
694
  </div>
704
-
705
- <pre class="example">
706
- &gt; ruby answer.rb 5 3
707
- 8
708
- 2
709
- 15
710
- 1
711
- </pre>
712
695
  </div>
713
696
  </div>
714
697
  </div>
@@ -738,7 +721,6 @@ print text
738
721
  </div>
739
722
  </div>
740
723
 
741
-
742
724
  <div id="outline-container-sec-9-2" class="outline-3">
743
725
  <h3 id="sec-9-2"><span class="section-number-3">9.2</span> read_line.rb</h3>
744
726
  <div class="outline-text-3" id="text-9-2">
@@ -761,7 +743,6 @@ end
761
743
  </div>
762
744
  </div>
763
745
 
764
-
765
746
  <div id="outline-container-sec-9-3" class="outline-3">
766
747
  <h3 id="sec-9-3"><span class="section-number-3">9.3</span> simple_grep.rb</h3>
767
748
  <div class="outline-text-3" id="text-9-3">
@@ -823,10 +804,12 @@ Hello, Ruby.
823
804
 
824
805
 
825
806
 
826
-
827
807
  <div id="outline-container-sec-11" class="outline-2">
828
808
  <h2 id="sec-11"><span class="section-number-2">11</span> 別のファイルを取り込む</h2>
829
809
  <div class="outline-text-2" id="text-11">
810
+ </div><div id="outline-container-sec-11-1" class="outline-3">
811
+ <h3 id="sec-11-1"><span class="section-number-3">11.1</span> ディレクトリ内のファイルの取り込み</h3>
812
+ <div class="outline-text-3" id="text-11-1">
830
813
  <div class="org-src-container">
831
814
 
832
815
  <pre class="src src-ruby">def simple_grep(pattern, filename)
@@ -851,10 +834,11 @@ simple_grep(pattern, filename)
851
834
  </pre>
852
835
  </div>
853
836
  </div>
837
+ </div>
854
838
 
855
- <div id="outline-container-sec-11-1" class="outline-3">
856
- <h3 id="sec-11-1"><span class="section-number-3">11.1</span> Rubyの標準ライブラリ</h3>
857
- <div class="outline-text-3" id="text-11-1">
839
+ <div id="outline-container-sec-11-2" class="outline-3">
840
+ <h3 id="sec-11-2"><span class="section-number-3">11.2</span> Rubyの標準ライブラリ</h3>
841
+ <div class="outline-text-3" id="text-11-2">
858
842
  <div class="org-src-container">
859
843
 
860
844
  <pre class="src src-ruby">require "date"
@@ -869,7 +853,7 @@ puts(days.to_i)
869
853
  </div>
870
854
  <div id="postamble" class="status">
871
855
  <p class="author">Author: Shun Takahashi</p>
872
- <p class="date">Created: 2018-08-04 04:56</p>
856
+ <p class="date">Created: 2018-08-09 17:09</p>
873
857
  <p class="creator"><a href="http://www.gnu.org/software/emacs/">Emacs</a> 25.3.1 (<a href="http://orgmode.org">Org</a> mode 8.2.10)</p>
874
858
  <p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
875
859
  </div>