ruby_learner 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +5 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +6 -0
  7. data/Gemfile.lock +58 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +65 -0
  10. data/Rakefile +6 -0
  11. data/bin/console +14 -0
  12. data/bin/new_terminal +25 -0
  13. data/bin/setup +8 -0
  14. data/docs/happy_ruby/RussOlsen_EloquentRuby_c1.pdf +0 -0
  15. data/docs/happy_ruby/RussOlsen_EloquentRuby_c5.pdf +0 -0
  16. data/docs/happy_ruby/TanoshiiRuby_v3_c23.pdf +0 -0
  17. data/docs/happy_ruby/TanoshiiRuby_v5_c1.pdf +0 -0
  18. data/docs/happy_ruby/TanoshiiRuby_v5_c2-3.pdf +0 -0
  19. data/docs/happy_ruby/c2.ipynb +479 -0
  20. data/docs/happy_ruby/c3_4.ipynb +237 -0
  21. data/docs/seminar/8-1.org +18 -0
  22. data/exe/ruby_learner +5 -0
  23. data/lib/ruby_learner/h.rb +14 -0
  24. data/lib/ruby_learner/methods.rb +131 -0
  25. data/lib/ruby_learner/random_h.rb +16 -0
  26. data/lib/ruby_learner/ruby_learner.rb +43 -0
  27. data/lib/ruby_learner/sequential_h.rb +15 -0
  28. data/lib/ruby_learner/typing_practice.rb +21 -0
  29. data/lib/ruby_learner/version.rb +3 -0
  30. data/questions/random_check/.rspec +1 -0
  31. data/questions/random_check/random_h.rb +16 -0
  32. data/questions/random_check/section_1/.rspec +1 -0
  33. data/questions/random_check/section_1/lib/answer.rb +15 -0
  34. data/questions/random_check/section_1/lib/sentence.org +9 -0
  35. data/questions/random_check/section_1/lib/workplace.rb +5 -0
  36. data/questions/random_check/section_1/spec/spec_helper.rb +100 -0
  37. data/questions/random_check/section_1/spec/workplace_spec.rb +10 -0
  38. data/questions/random_check/section_2/.rspec +1 -0
  39. data/questions/random_check/section_2/lib/answer.rb +17 -0
  40. data/questions/random_check/section_2/lib/sentence.org +12 -0
  41. data/questions/random_check/section_2/lib/workplace.rb +5 -0
  42. data/questions/random_check/section_2/spec/.rspec +1 -0
  43. data/questions/random_check/section_2/spec/spec_helper.rb +100 -0
  44. data/questions/random_check/section_2/spec/workplace_spec.rb +11 -0
  45. data/questions/sequential_check/section_1/part_1/lib/answer.rb +9 -0
  46. data/questions/sequential_check/section_1/part_1/lib/sentence.org +9 -0
  47. data/questions/sequential_check/section_1/part_1/lib/workplace.rb +5 -0
  48. data/questions/sequential_check/section_1/part_1/spec/spec_helper.rb +100 -0
  49. data/questions/sequential_check/section_1/part_1/spec/workplace_spec.rb +10 -0
  50. data/questions/sequential_check/section_1/part_2/lib/answer.rb +16 -0
  51. data/questions/sequential_check/section_1/part_2/lib/sentence.org +12 -0
  52. data/questions/sequential_check/section_1/part_2/lib/workplace.rb +5 -0
  53. data/questions/sequential_check/section_1/part_2/spec/.rspec +1 -0
  54. data/questions/sequential_check/section_1/part_2/spec/spec_helper.rb +100 -0
  55. data/questions/sequential_check/section_1/part_2/spec/workplace_spec.rb +11 -0
  56. data/ruby_learner.gemspec +41 -0
  57. data/takahashi/docs/README.org +139 -0
  58. data/takahashi/docs/drill.html +875 -0
  59. data/takahashi/docs/drill.html~ +877 -0
  60. data/takahashi/docs/drill.org +446 -0
  61. data/takahashi/docs/ruby_for_beginner.html +2642 -0
  62. data/takahashi/docs/ruby_for_beginner.org +1430 -0
  63. data/takahashi/sample_prog/answer/10_1.rb +5 -0
  64. data/takahashi/sample_prog/answer/11_1.rb +5 -0
  65. data/takahashi/sample_prog/answer/11_2.rb +4 -0
  66. data/takahashi/sample_prog/answer/1_1.rb +1 -0
  67. data/takahashi/sample_prog/answer/1_2.rb +1 -0
  68. data/takahashi/sample_prog/answer/1_3.rb +1 -0
  69. data/takahashi/sample_prog/answer/2_1.rb +5 -0
  70. data/takahashi/sample_prog/answer/2_2.rb +12 -0
  71. data/takahashi/sample_prog/answer/3_1.rb +10 -0
  72. data/takahashi/sample_prog/answer/4_1.rb +7 -0
  73. data/takahashi/sample_prog/answer/5_1.rb +6 -0
  74. data/takahashi/sample_prog/answer/5_2.rb +3 -0
  75. data/takahashi/sample_prog/answer/6_1.rb +3 -0
  76. data/takahashi/sample_prog/answer/6_2.rb +5 -0
  77. data/takahashi/sample_prog/answer/6_3.rb +5 -0
  78. data/takahashi/sample_prog/answer/6_4.rb +7 -0
  79. data/takahashi/sample_prog/answer/7_1.rb +3 -0
  80. data/takahashi/sample_prog/answer/7_2.rb +8 -0
  81. data/takahashi/sample_prog/answer/9_1.rb +3 -0
  82. data/takahashi/sample_prog/answer/9_2.rb +5 -0
  83. data/takahashi/sample_prog/answer/9_3.rb +10 -0
  84. data/takahashi/sample_prog/answer/hello.rb +3 -0
  85. data/workshop/.rspec +1 -0
  86. data/workshop/emacs.d/ac-comphist.dat +50 -0
  87. data/workshop/emacs.d/cp5022x.el +156 -0
  88. data/workshop/emacs.d/elpa/archives/gnu/archive-contents +1240 -0
  89. data/workshop/emacs.d/elpa/archives/melpa/archive-contents +2 -0
  90. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/auto-complete-autoloads.el +65 -0
  91. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/auto-complete-config.el +551 -0
  92. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/auto-complete-config.elc +0 -0
  93. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/auto-complete-pkg.el +6 -0
  94. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/auto-complete.el +2164 -0
  95. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/auto-complete.elc +0 -0
  96. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/ada-mode +72 -0
  97. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/c++-mode +99 -0
  98. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/c-mode +55 -0
  99. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/caml-mode +231 -0
  100. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/clojure-mode +580 -0
  101. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/clojurescript-mode +475 -0
  102. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/coq-mode +278 -0
  103. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/css-mode +874 -0
  104. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/erlang-mode +216 -0
  105. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/ess-julia-mode +37 -0
  106. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/go-mode +25 -0
  107. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/haskell-mode +679 -0
  108. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/java-mode +53 -0
  109. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/js-mode +148 -0
  110. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/julia-mode +37 -0
  111. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/lua-mode +21 -0
  112. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/nim-mode +70 -0
  113. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/objc-mode +161 -0
  114. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/octave-mode +46 -0
  115. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/php-mode +6144 -0
  116. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/python-mode +379 -0
  117. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/qml-mode +183 -0
  118. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/ruby-mode +181 -0
  119. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/scala-mode +1347 -0
  120. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/scheme-mode +216 -0
  121. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/sclang-mode +1481 -0
  122. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/sh-mode +182 -0
  123. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/swift-mode +87 -0
  124. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/tcl-mode +172 -0
  125. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/ts-mode +797 -0
  126. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/tuareg-mode +231 -0
  127. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/verilog-mode +313 -0
  128. data/workshop/emacs.d/elpa/better-defaults-20170613.2104/better-defaults-autoloads.el +16 -0
  129. data/workshop/emacs.d/elpa/better-defaults-20170613.2104/better-defaults-pkg.el +2 -0
  130. data/workshop/emacs.d/elpa/better-defaults-20170613.2104/better-defaults.el +90 -0
  131. data/workshop/emacs.d/elpa/better-defaults-20170613.2104/better-defaults.elc +0 -0
  132. data/workshop/emacs.d/elpa/haml-mode-20170923.2153/haml-mode-autoloads.el +26 -0
  133. data/workshop/emacs.d/elpa/haml-mode-20170923.2153/haml-mode-pkg.el +2 -0
  134. data/workshop/emacs.d/elpa/haml-mode-20170923.2153/haml-mode.el +877 -0
  135. data/workshop/emacs.d/elpa/haml-mode-20170923.2153/haml-mode.elc +0 -0
  136. data/workshop/emacs.d/elpa/haml-mode-readme.txt +8 -0
  137. data/workshop/emacs.d/elpa/material-theme-20171123.1040/material-light-theme.el +918 -0
  138. data/workshop/emacs.d/elpa/material-theme-20171123.1040/material-light-theme.elc +0 -0
  139. data/workshop/emacs.d/elpa/material-theme-20171123.1040/material-theme-autoloads.el +32 -0
  140. data/workshop/emacs.d/elpa/material-theme-20171123.1040/material-theme-pkg.el +8 -0
  141. data/workshop/emacs.d/elpa/material-theme-20171123.1040/material-theme.el +912 -0
  142. data/workshop/emacs.d/elpa/material-theme-20171123.1040/material-theme.elc +0 -0
  143. data/workshop/emacs.d/elpa/ox-bibtex-chinese-readme.txt +21 -0
  144. data/workshop/emacs.d/elpa/popup-20160709.729/popup-autoloads.el +15 -0
  145. data/workshop/emacs.d/elpa/popup-20160709.729/popup-pkg.el +2 -0
  146. data/workshop/emacs.d/elpa/popup-20160709.729/popup.el +1432 -0
  147. data/workshop/emacs.d/elpa/popup-20160709.729/popup.elc +0 -0
  148. data/workshop/emacs.d/elpa/yaml-mode-20180212.1556/yaml-mode-autoloads.el +33 -0
  149. data/workshop/emacs.d/elpa/yaml-mode-20180212.1556/yaml-mode-pkg.el +2 -0
  150. data/workshop/emacs.d/elpa/yaml-mode-20180212.1556/yaml-mode.el +470 -0
  151. data/workshop/emacs.d/elpa/yaml-mode-20180212.1556/yaml-mode.elc +0 -0
  152. data/workshop/emacs.d/elpa/yaml-mode-readme.txt +25 -0
  153. data/workshop/emacs.d/haml-mode-master/.gitignore +1 -0
  154. data/workshop/emacs.d/haml-mode-master/.mailmap +2 -0
  155. data/workshop/emacs.d/haml-mode-master/MIT-LICENSE +20 -0
  156. data/workshop/emacs.d/haml-mode-master/README.md +47 -0
  157. data/workshop/emacs.d/haml-mode-master/haml-mode.el +887 -0
  158. data/workshop/emacs.d/iceberg_theme.el +202 -0
  159. data/workshop/emacs.d/init-open-recentf.el +133 -0
  160. data/workshop/emacs.d/init.el +229 -0
  161. data/workshop/emacs.d/inits/line-num.el +264 -0
  162. data/workshop/emacs.d/install-elisp.el +366 -0
  163. data/workshop/emacs.d/markdown-mode/markdown-mode.el +5978 -0
  164. data/workshop/emacs.d/notes +12 -0
  165. data/workshop/emacs.d/processing-mode/processing-mode.el +275 -0
  166. data/workshop/emacs.d/recentf +31 -0
  167. data/workshop/emacs.d/ruby-mode/inf-ruby.el +416 -0
  168. data/workshop/emacs.d/ruby-mode/rdoc-mode.el +130 -0
  169. data/workshop/emacs.d/ruby-mode/ruby-electric.el +205 -0
  170. data/workshop/emacs.d/ruby-mode/ruby-mode.el +1496 -0
  171. data/workshop/emacs.d/ruby-mode/ruby-style.el +78 -0
  172. data/workshop/emacs.d/ruby-mode/rubydb2x.el +104 -0
  173. data/workshop/emacs.d/ruby-mode/rubydb3x.el +115 -0
  174. data/workshop/emacs.d/ruby_learner_init.el +244 -0
  175. data/workshop/emacs.d/themes/dracula-theme.el +431 -0
  176. data/workshop/emacs.d/themes/iceberg-theme.el +205 -0
  177. data/workshop/emacs.d/themes/my-misterioso-theme.el +109 -0
  178. data/workshop/emacs.d/themes/my-wombat-theme.el +121 -0
  179. data/workshop/emacs.d/wiki-mode/wiki.el +976 -0
  180. data/workshop/emacs_help.org +34 -0
  181. data/workshop/lib/answer.rb +1 -0
  182. data/workshop/lib/sentence.org +1 -0
  183. data/workshop/lib/workplace.rb +1 -0
  184. data/workshop/restore/empty.rb +0 -0
  185. data/workshop/spec/spec_helper.rb +100 -0
  186. data/workshop/spec/workplace_spec.rb +1 -0
  187. data/workshop/training_data.txt +3 -0
  188. metadata +343 -0
@@ -0,0 +1,875 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="jp" xml:lang="jp">
5
+ <head>
6
+ <title>はじめてのRuby</title>
7
+ <!-- 2018-08-04 土 06:48 -->
8
+ <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
9
+ <meta name="generator" content="Org-mode" />
10
+ <meta name="author" content="Shun Takahashi" />
11
+ <style type="text/css">
12
+ <!--/*--><![CDATA[/*><!--*/
13
+ .title { text-align: center; }
14
+ .todo { font-family: monospace; color: red; }
15
+ .done { color: green; }
16
+ .tag { background-color: #eee; font-family: monospace;
17
+ padding: 2px; font-size: 80%; font-weight: normal; }
18
+ .timestamp { color: #bebebe; }
19
+ .timestamp-kwd { color: #5f9ea0; }
20
+ .right { margin-left: auto; margin-right: 0px; text-align: right; }
21
+ .left { margin-left: 0px; margin-right: auto; text-align: left; }
22
+ .center { margin-left: auto; margin-right: auto; text-align: center; }
23
+ .underline { text-decoration: underline; }
24
+ #postamble p, #preamble p { font-size: 90%; margin: .2em; }
25
+ p.verse { margin-left: 3%; }
26
+ pre {
27
+ border: 1px solid #ccc;
28
+ box-shadow: 3px 3px 3px #eee;
29
+ padding: 8pt;
30
+ font-family: monospace;
31
+ overflow: auto;
32
+ margin: 1.2em;
33
+ }
34
+ pre.src {
35
+ position: relative;
36
+ overflow: visible;
37
+ padding-top: 1.2em;
38
+ }
39
+ pre.src:before {
40
+ display: none;
41
+ position: absolute;
42
+ background-color: white;
43
+ top: -10px;
44
+ right: 10px;
45
+ padding: 3px;
46
+ border: 1px solid black;
47
+ }
48
+ pre.src:hover:before { display: inline;}
49
+ pre.src-sh:before { content: 'sh'; }
50
+ pre.src-bash:before { content: 'sh'; }
51
+ pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
52
+ pre.src-R:before { content: 'R'; }
53
+ pre.src-perl:before { content: 'Perl'; }
54
+ pre.src-java:before { content: 'Java'; }
55
+ pre.src-sql:before { content: 'SQL'; }
56
+
57
+ table { border-collapse:collapse; }
58
+ caption.t-above { caption-side: top; }
59
+ caption.t-bottom { caption-side: bottom; }
60
+ td, th { vertical-align:top; }
61
+ th.right { text-align: center; }
62
+ th.left { text-align: center; }
63
+ th.center { text-align: center; }
64
+ td.right { text-align: right; }
65
+ td.left { text-align: left; }
66
+ td.center { text-align: center; }
67
+ dt { font-weight: bold; }
68
+ .footpara:nth-child(2) { display: inline; }
69
+ .footpara { display: block; }
70
+ .footdef { margin-bottom: 1em; }
71
+ .figure { padding: 1em; }
72
+ .figure p { text-align: center; }
73
+ .inlinetask {
74
+ padding: 10px;
75
+ border: 2px solid gray;
76
+ margin: 10px;
77
+ background: #ffffcc;
78
+ }
79
+ #org-div-home-and-up
80
+ { text-align: right; font-size: 70%; white-space: nowrap; }
81
+ textarea { overflow-x: auto; }
82
+ .linenr { font-size: smaller }
83
+ .code-highlighted { background-color: #ffff00; }
84
+ .org-info-js_info-navigation { border-style: none; }
85
+ #org-info-js_console-label
86
+ { font-size: 10px; font-weight: bold; white-space: nowrap; }
87
+ .org-info-js_search-highlight
88
+ { background-color: #ffff00; color: #000000; font-weight: bold; }
89
+ /*]]>*/-->
90
+ </style>
91
+ <link rel="stylesheet" type="text/css" href="http://www.pirilampo.org/styles/readtheorg/css/htmlize.css"/>
92
+ <link rel="stylesheet" type="text/css" href="http://www.pirilampo.org/styles/readtheorg/css/readtheorg.css"/>
93
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
94
+ <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
95
+ <script type="text/javascript" src="http://www.pirilampo.org/styles/lib/js/jquery.stickytableheaders.js"></script>
96
+ <script type="text/javascript" src="http://www.pirilampo.org/styles/readtheorg/js/readtheorg.js"></script>
97
+ <script type="text/javascript">
98
+ /*
99
+ @licstart The following is the entire license notice for the
100
+ JavaScript code in this tag.
101
+
102
+ Copyright (C) 2012-2013 Free Software Foundation, Inc.
103
+
104
+ The JavaScript code in this tag is free software: you can
105
+ redistribute it and/or modify it under the terms of the GNU
106
+ General Public License (GNU GPL) as published by the Free Software
107
+ Foundation, either version 3 of the License, or (at your option)
108
+ any later version. The code is distributed WITHOUT ANY WARRANTY;
109
+ without even the implied warranty of MERCHANTABILITY or FITNESS
110
+ FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
111
+
112
+ As additional permission under GNU GPL version 3 section 7, you
113
+ may distribute non-source (e.g., minimized or compacted) forms of
114
+ that code without the copy of the GNU GPL normally required by
115
+ section 4, provided you include this license notice and a URL
116
+ through which recipients can access the Corresponding Source.
117
+
118
+
119
+ @licend The above is the entire license notice
120
+ for the JavaScript code in this tag.
121
+ */
122
+ <!--/*--><![CDATA[/*><!--*/
123
+ function CodeHighlightOn(elem, id)
124
+ {
125
+ var target = document.getElementById(id);
126
+ if(null != target) {
127
+ elem.cacheClassElem = elem.className;
128
+ elem.cacheClassTarget = target.className;
129
+ target.className = "code-highlighted";
130
+ elem.className = "code-highlighted";
131
+ }
132
+ }
133
+ function CodeHighlightOff(elem, id)
134
+ {
135
+ var target = document.getElementById(id);
136
+ if(elem.cacheClassElem)
137
+ elem.className = elem.cacheClassElem;
138
+ if(elem.cacheClassTarget)
139
+ target.className = elem.cacheClassTarget;
140
+ }
141
+ /*]]>*///-->
142
+ </script>
143
+ <script type="text/javascript" src="http://orgmode.org/mathjax/MathJax.js"></script>
144
+ <script type="text/javascript">
145
+ <!--/*--><![CDATA[/*><!--*/
146
+ MathJax.Hub.Config({
147
+ // Only one of the two following lines, depending on user settings
148
+ // First allows browser-native MathML display, second forces HTML/CSS
149
+ // config: ["MMLorHTML.js"], jax: ["input/TeX"],
150
+ jax: ["input/TeX", "output/HTML-CSS"],
151
+ extensions: ["tex2jax.js","TeX/AMSmath.js","TeX/AMSsymbols.js",
152
+ "TeX/noUndefined.js"],
153
+ tex2jax: {
154
+ inlineMath: [ ["\\(","\\)"] ],
155
+ displayMath: [ ['$$','$$'], ["\\[","\\]"], ["\\begin{displaymath}","\\end{displaymath}"] ],
156
+ skipTags: ["script","noscript","style","textarea","pre","code"],
157
+ ignoreClass: "tex2jax_ignore",
158
+ processEscapes: false,
159
+ processEnvironments: true,
160
+ preview: "TeX"
161
+ },
162
+ showProcessingMessages: true,
163
+ displayAlign: "center",
164
+ displayIndent: "2em",
165
+
166
+ "HTML-CSS": {
167
+ scale: 100,
168
+ availableFonts: ["STIX","TeX"],
169
+ preferredFont: "TeX",
170
+ webFont: "TeX",
171
+ imageFont: "TeX",
172
+ showMathMenu: true,
173
+ },
174
+ MMLorHTML: {
175
+ prefer: {
176
+ MSIE: "MML",
177
+ Firefox: "MML",
178
+ Opera: "HTML",
179
+ other: "HTML"
180
+ }
181
+ }
182
+ });
183
+ /*]]>*///-->
184
+ </script>
185
+ </head>
186
+ <body>
187
+ <div id="content">
188
+ <h1 class="title">はじめてのRuby</h1>
189
+ <div id="table-of-contents">
190
+ <h2>Table of Contents</h2>
191
+ <div id="text-table-of-contents">
192
+ <ul>
193
+ <li><a href="#sec-1">1. print,puts,pメソッド</a>
194
+ <ul>
195
+ <li><a href="#sec-1-1">1.1. helloruby.rb</a></li>
196
+ <li><a href="#sec-1-2">1.2. helloruby_2.rb</a></li>
197
+ <li><a href="#sec-1-3">1.3. p_method.rb</a></li>
198
+ <li><a href="#sec-1-4">1.4. kiritsubo.rb</a></li>
199
+ </ul>
200
+ </li>
201
+ <li><a href="#sec-2">2. コマンドラインからのデータの入力</a>
202
+ <ul>
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>
205
+ </ul>
206
+ </li>
207
+ <li><a href="#sec-3">3. 変数</a>
208
+ <ul>
209
+ <li><a href="#sec-3-1">3.1. area_volume.rb</a></li>
210
+ </ul>
211
+ </li>
212
+ <li><a href="#sec-4">4. 条件判断</a>
213
+ <ul>
214
+ <li><a href="#sec-4-1">4.1. greater_smaller.rb</a></li>
215
+ <li><a href="#sec-4-2">4.2. greater_smaller_else.rb</a></li>
216
+ </ul>
217
+ </li>
218
+ <li><a href="#sec-5">5. 繰り返し</a>
219
+ <ul>
220
+ <li><a href="#sec-5-1">5.1. 1_to_n.rb</a></li>
221
+ <li><a href="#sec-5-2">5.2. five_times.rb</a></li>
222
+ </ul>
223
+ </li>
224
+ <li><a href="#sec-6">6. 配列</a>
225
+ <ul>
226
+ <li><a href="#sec-6-1">6.1. 配列からオブジェクトを取り出す</a></li>
227
+ <li><a href="#sec-6-2">6.2. 配列にオブジェクトを格納する</a></li>
228
+ <li><a href="#sec-6-3">6.3. 配列の大きさ</a></li>
229
+ <li><a href="#sec-6-4">6.4. 配列と繰り返し</a></li>
230
+ </ul>
231
+ </li>
232
+ <li><a href="#sec-7">7. ハッシュ</a>
233
+ <ul>
234
+ <li><a href="#sec-7-1">7.1. シンボル</a></li>
235
+ <li><a href="#sec-7-2">7.2. ハッシュの操作</a></li>
236
+ </ul>
237
+ </li>
238
+ <li><a href="#sec-8">8. 正規表現</a>
239
+ <ul>
240
+ <li><a href="#sec-8-1">8.1. パターンとマッチング</a></li>
241
+ </ul>
242
+ </li>
243
+ <li><a href="#sec-9">9. ファイルからの読み込み</a>
244
+ <ul>
245
+ <li><a href="#sec-9-1">9.1. read_text.rb</a></li>
246
+ <li><a href="#sec-9-2">9.2. read_line.rb</a></li>
247
+ <li><a href="#sec-9-3">9.3. simple_grep.rb</a></li>
248
+ </ul>
249
+ </li>
250
+ <li><a href="#sec-10">10. メソッドの作成</a>
251
+ <ul>
252
+ <li><a href="#sec-10-1">10.1. hello_ruby2.rb</a></li>
253
+ </ul>
254
+ </li>
255
+ <li><a href="#sec-11">11. 別のファイルを取り込む</a>
256
+ <ul>
257
+ <li><a href="#sec-11-1">11.1. ディレクトリ内のファイルの取り込み</a></li>
258
+ <li><a href="#sec-11-2">11.2. Rubyの標準ライブラリ</a></li>
259
+ </ul>
260
+ </li>
261
+ </ul>
262
+ </div>
263
+ </div>
264
+
265
+
266
+ <div id="outline-container-sec-1" class="outline-2">
267
+ <h2 id="sec-1"><span class="section-number-2">1</span> print,puts,pメソッド</h2>
268
+ <div class="outline-text-2" id="text-1">
269
+ </div><div id="outline-container-sec-1-1" class="outline-3">
270
+ <h3 id="sec-1-1"><span class="section-number-3">1.1</span> helloruby.rb</h3>
271
+ <div class="outline-text-3" id="text-1-1">
272
+ <p>
273
+ 「Hello, Ruby.」という文字列を出力するプログラムを作成せよ
274
+ </p>
275
+
276
+ <div class="org-src-container">
277
+
278
+ <pre class="src src-ruby">print('Hello, Ruby.\n')
279
+ </pre>
280
+ </div>
281
+
282
+ <pre class="example">
283
+ Hello, Ruby.
284
+ </pre>
285
+ </div>
286
+ </div>
287
+
288
+ <div id="outline-container-sec-1-2" class="outline-3">
289
+ <h3 id="sec-1-2"><span class="section-number-3">1.2</span> helloruby_2.rb</h3>
290
+ <div class="outline-text-3" id="text-1-2">
291
+ <p>
292
+ 「Hello, "Ruby".」という文字列を出力するプログラムを作成せよ
293
+ </p>
294
+
295
+ <div class="org-src-container">
296
+
297
+ <pre class="src src-ruby">print("Hello, \"Ruby\".\n")
298
+ </pre>
299
+ </div>
300
+
301
+ <pre class="example">
302
+ &gt; helloruby_2.rb
303
+ Hello,"Ruby".
304
+ </pre>
305
+ </div>
306
+ </div>
307
+
308
+ <div id="outline-container-sec-1-3" class="outline-3">
309
+ <h3 id="sec-1-3"><span class="section-number-3">1.3</span> p_method.rb</h3>
310
+ <div class="outline-text-3" id="text-1-3">
311
+ <p>
312
+ 「"Hello,\n\tRuby."」という文字列を出力するプログラムを作成せよ
313
+ </p>
314
+
315
+ <div class="org-src-container">
316
+
317
+ <pre class="src src-ruby">p "Hello,\n\tRuby."
318
+ </pre>
319
+ </div>
320
+ </div>
321
+ </div>
322
+
323
+
324
+
325
+ <div id="outline-container-sec-1-4" class="outline-3">
326
+ <h3 id="sec-1-4"><span class="section-number-3">1.4</span> kiritsubo.rb</h3>
327
+ <div class="outline-text-3" id="text-1-4">
328
+ </div>
329
+ </div>
330
+ </div>
331
+
332
+ <div id="outline-container-sec-2" class="outline-2">
333
+ <h2 id="sec-2"><span class="section-number-2">2</span> コマンドラインからのデータの入力</h2>
334
+ <div class="outline-text-2" id="text-2">
335
+ </div><div id="outline-container-sec-2-1" class="outline-3">
336
+ <h3 id="sec-2-1"><span class="section-number-3">2.1</span> print_argv.rb</h3>
337
+ <div class="outline-text-3" id="text-2-1">
338
+ <p>
339
+ コマンドラインから引数を5つ入力として受け取り、出力するプログラム
340
+ </p>
341
+
342
+ <div class="org-src-container">
343
+
344
+ <pre class="src src-ruby"># List3.1 print_argv.rb
345
+ puts "最初の引数: #{ARGV[0]}"
346
+ puts "2番目の引数: #{ARGV[1]}"
347
+ puts "3番目の引数: #{ARGV[2]}"
348
+ puts "4番目の引数: #{ARGV[3]}"
349
+ puts "5番目の引数: #{ARGV[4]}"
350
+ </pre>
351
+ </div>
352
+
353
+ <pre class="example">
354
+ 実行例
355
+ &gt; ruby print_argv.rb 1st 2nd 3rd 4th 5th
356
+ 最初の引数: 1st
357
+ 2番目の引数: 2nd
358
+ 3番目の引数: 3rd
359
+ 4番目の引数: 4th
360
+ 5番目の引数: 5th
361
+ </pre>
362
+ </div>
363
+ </div>
364
+
365
+
366
+
367
+ <div id="outline-container-sec-2-2" class="outline-3">
368
+ <h3 id="sec-2-2"><span class="section-number-3">2.2</span> arg_arith.rb</h3>
369
+ <div class="outline-text-3" id="text-2-2">
370
+ <p>
371
+ コマンドラインから数値を2つ受け取り、和、差、積、商を表示するプログラム
372
+ </p>
373
+
374
+ <div class="org-src-container">
375
+
376
+ <pre class="src src-ruby">num0 = ARGV[0].to_i
377
+ num1 = ARGV[1].to_i
378
+
379
+ puts "#{num0 + num1}"
380
+ puts "#{num0 - num1}"
381
+ puts "#{num0 * num1}"
382
+ puts "#{num0 / num1}"
383
+ </pre>
384
+ </div>
385
+
386
+ <pre class="example">
387
+ &gt; ruby answer.rb 5 3
388
+ 8
389
+ 2
390
+ 15
391
+ 1
392
+ </pre>
393
+ </div>
394
+ </div>
395
+ </div>
396
+
397
+ <div id="outline-container-sec-3" class="outline-2">
398
+ <h2 id="sec-3"><span class="section-number-2">3</span> 変数</h2>
399
+ <div class="outline-text-2" id="text-3">
400
+ </div><div id="outline-container-sec-3-1" class="outline-3">
401
+ <h3 id="sec-3-1"><span class="section-number-3">3.1</span> area_volume.rb</h3>
402
+ <div class="outline-text-3" id="text-3-1">
403
+ <p>
404
+ 3つの数値x、y、zを受け取り、縦x、横y、高さzの直方体の表面積と体積を求めるプログラム
405
+ </p>
406
+
407
+ <div class="org-src-container">
408
+
409
+ <pre class="src src-ruby">x = ARGV[0].to_i
410
+ y = ARGV[1].to_i
411
+ z = ARGV[2].to_i
412
+
413
+ area = (x*y + y*z + z*x) * 2
414
+ volume = x * y * z
415
+
416
+ print "表面積=", area, "\n"
417
+ print "体積=" volume, "\n"
418
+ </pre>
419
+ </div>
420
+
421
+ <pre class="example">
422
+ &gt; ruby area_volume.rb 10 20 30
423
+ 表面積=2200
424
+ 体積=6000
425
+ </pre>
426
+ </div>
427
+ </div>
428
+ </div>
429
+
430
+ <div id="outline-container-sec-4" class="outline-2">
431
+ <h2 id="sec-4"><span class="section-number-2">4</span> 条件判断</h2>
432
+ <div class="outline-text-2" id="text-4">
433
+ </div><div id="outline-container-sec-4-1" class="outline-3">
434
+ <h3 id="sec-4-1"><span class="section-number-3">4.1</span> greater_smaller.rb</h3>
435
+ <div class="outline-text-3" id="text-4-1">
436
+ <p>
437
+ 数値を1つ引数として受け取り、それが10以上ならば「greater」、9以下ならば「smaller」と出力するプログラム
438
+ </p>
439
+
440
+ <div class="org-src-container">
441
+
442
+ <pre class="src src-ruby">a = ARGV[0].to_i
443
+
444
+ if a &gt;= 10
445
+ print "greater\n"
446
+ end
447
+ if a &lt;= 9
448
+ print "smaller\n"
449
+ end
450
+ </pre>
451
+ </div>
452
+
453
+ <pre class="example">
454
+ &gt;ruby greater_smaller_else.rb 20
455
+ greater
456
+
457
+ &gt;ruby greater_smaller_else.rb 5
458
+ smaller
459
+ </pre>
460
+ </div>
461
+ </div>
462
+
463
+ <div id="outline-container-sec-4-2" class="outline-3">
464
+ <h3 id="sec-4-2"><span class="section-number-3">4.2</span> greater_smaller_else.rb</h3>
465
+ <div class="outline-text-3" id="text-4-2">
466
+ <p>
467
+ List1.6のプログラムと同じ処理を、elseを用いて実行するプログラム
468
+ </p>
469
+
470
+ <div class="org-src-container">
471
+
472
+ <pre class="src src-ruby">a = ARGV[0].to_i
473
+
474
+ if a &gt;= 10
475
+ print "greater\n"
476
+ else
477
+ print "smaller\n"
478
+ </pre>
479
+ </div>
480
+
481
+ <pre class="example">
482
+ &gt;ruby greater_smaller_else.rb 20
483
+ greater
484
+
485
+ &gt;ruby greater_smaller_else.rb 5
486
+ smaller
487
+ </pre>
488
+ </div>
489
+ </div>
490
+ </div>
491
+
492
+ <div id="outline-container-sec-5" class="outline-2">
493
+ <h2 id="sec-5"><span class="section-number-2">5</span> 繰り返し</h2>
494
+ <div class="outline-text-2" id="text-5">
495
+ </div><div id="outline-container-sec-5-1" class="outline-3">
496
+ <h3 id="sec-5-1"><span class="section-number-3">5.1</span> 1_to_n.rb</h3>
497
+ <div class="outline-text-3" id="text-5-1">
498
+ <p>
499
+ 入力された1つの数値nを引数として受け取り、1からnまでの数を順番に表示するプログラムを作成せよ
500
+ </p>
501
+
502
+ <div class="org-src-container">
503
+
504
+ <pre class="src src-ruby">n = ARGV[0].to_i
505
+ i = 1
506
+ while i &lt;= n
507
+ print i, "\n"
508
+ i = i + 1
509
+ end
510
+ </pre>
511
+ </div>
512
+
513
+ <pre class="example">
514
+ &gt; ruby 1_to_n.rb 5
515
+ 1
516
+ 2
517
+ 3
518
+ 4
519
+ 5
520
+ </pre>
521
+ </div>
522
+ </div>
523
+
524
+ <div id="outline-container-sec-5-2" class="outline-3">
525
+ <h3 id="sec-5-2"><span class="section-number-3">5.2</span> five_times.rb</h3>
526
+ <div class="outline-text-3" id="text-5-2">
527
+ <p>
528
+ 「All work and no play makes Jack a dull boy.」と5行表示するプログラム
529
+ </p>
530
+
531
+ <div class="org-src-container">
532
+
533
+ <pre class="src src-ruby">5.times do
534
+ print "All work and no play makes Jack a dull boy."
535
+ end
536
+ </pre>
537
+ </div>
538
+ </div>
539
+ </div>
540
+ </div>
541
+
542
+
543
+
544
+ <div id="outline-container-sec-6" class="outline-2">
545
+ <h2 id="sec-6"><span class="section-number-2">6</span> 配列</h2>
546
+ <div class="outline-text-2" id="text-6">
547
+ </div><div id="outline-container-sec-6-1" class="outline-3">
548
+ <h3 id="sec-6-1"><span class="section-number-3">6.1</span> 配列からオブジェクトを取り出す</h3>
549
+ <div class="outline-text-3" id="text-6-1">
550
+ <p>
551
+ 配列のn番目の要素を取り出し、表示するプログラム
552
+ </p>
553
+
554
+ <div class="org-src-container">
555
+
556
+ <pre class="src src-ruby">names = ["小林", "林", "高野", "森岡"]
557
+
558
+ print names[ARGV[0]]
559
+ </pre>
560
+ </div>
561
+
562
+ <div class="org-src-container">
563
+
564
+ <pre class="src src-ruby">&gt;ruby answer.rb 0
565
+ 小林
566
+ </pre>
567
+ </div>
568
+ </div>
569
+ </div>
570
+
571
+ <div id="outline-container-sec-6-2" class="outline-3">
572
+ <h3 id="sec-6-2"><span class="section-number-3">6.2</span> 配列にオブジェクトを格納する</h3>
573
+ <div class="outline-text-3" id="text-6-2">
574
+ <p>
575
+ 配列の先頭の要素をコマンドラインに入力した要素に変更するプログラム
576
+ </p>
577
+
578
+ <div class="org-src-container">
579
+
580
+ <pre class="src src-ruby">nums = [1, 2, 3]
581
+
582
+ nums[0] = ARGV[0]
583
+
584
+ print nums
585
+ </pre>
586
+ </div>
587
+
588
+
589
+ <pre class="example">
590
+ &gt; ruby answer.rb 5
591
+ [5, 2, 3]
592
+ </pre>
593
+ </div>
594
+ </div>
595
+
596
+ <div id="outline-container-sec-6-3" class="outline-3">
597
+ <h3 id="sec-6-3"><span class="section-number-3">6.3</span> 配列の大きさ</h3>
598
+ <div class="outline-text-3" id="text-6-3">
599
+ <p>
600
+ 配列を表示し、その配列の大きさも表示するプログラムを作成せよ
601
+ </p>
602
+
603
+ <div class="org-src-container">
604
+
605
+ <pre class="src src-ruby">names =
606
+
607
+ print names, "\n"
608
+
609
+ print names.size
610
+ </pre>
611
+ </div>
612
+ </div>
613
+ </div>
614
+
615
+ <div id="outline-container-sec-6-4" class="outline-3">
616
+ <h3 id="sec-6-4"><span class="section-number-3">6.4</span> 配列と繰り返し</h3>
617
+ <div class="outline-text-3" id="text-6-4">
618
+ <p>
619
+ 配列全体を表示してから、配列の要素を順に表示するプログラム
620
+ </p>
621
+
622
+ <div class="org-src-container">
623
+
624
+ <pre class="src src-ruby">names = ["小林", "林", "高野", "森岡"]
625
+
626
+ print names, "\n"
627
+
628
+ names.each do |n|
629
+ puts n
630
+ end
631
+ </pre>
632
+ </div>
633
+
634
+ <pre class="example">
635
+ &gt; ruby answer.rb
636
+ ["小林", "林", "高野", "森岡"]
637
+ 小林
638
+
639
+ 高野
640
+ 森岡
641
+ </pre>
642
+ </div>
643
+ </div>
644
+ </div>
645
+
646
+ <div id="outline-container-sec-7" class="outline-2">
647
+ <h2 id="sec-7"><span class="section-number-2">7</span> ハッシュ</h2>
648
+ <div class="outline-text-2" id="text-7">
649
+ </div><div id="outline-container-sec-7-1" class="outline-3">
650
+ <h3 id="sec-7-1"><span class="section-number-3">7.1</span> シンボル</h3>
651
+ <div class="outline-text-3" id="text-7-1">
652
+ <p>
653
+ コマンドラインから文字列を受け取り、シンボルに変換して表示するプログラム
654
+ </p>
655
+
656
+ <div class="org-src-container">
657
+
658
+ <pre class="src src-ruby">n = ARGV[0]
659
+
660
+ p n.to_sym
661
+ </pre>
662
+ </div>
663
+
664
+ <pre class="example">
665
+ &gt; ruby answer.rb hash
666
+ :hash
667
+ </pre>
668
+ </div>
669
+ </div>
670
+
671
+ <div id="outline-container-sec-7-2" class="outline-3">
672
+ <h3 id="sec-7-2"><span class="section-number-3">7.2</span> ハッシュの操作</h3>
673
+ <div class="outline-text-3" id="text-7-2">
674
+ <p>
675
+ :name, :furiganaというそれぞれのキーに"高橋", "タカハシ"というオブジェクトが格納されているハッシュを表示、さらに:telというキーに"000-1234-5678"を格納して再度表示するプログラム
676
+ </p>
677
+
678
+ <div class="org-src-container">
679
+
680
+ <pre class="src src-ruby">address = {name: "高橋", furigana: "タカハシ"}
681
+
682
+ puts address
683
+
684
+ address[:tel] = "000-1234-5678"
685
+
686
+ puts address
687
+ </pre>
688
+ </div>
689
+
690
+ <pre class="example">
691
+ &gt; ruby answer.rb
692
+ {:name=&gt;"高橋", :furigana=&gt;"タカハシ"}
693
+ {:name=&gt;"高橋", :furigana=&gt;"タカハシ", :tel=&gt;"000-1234-5678"}
694
+ </pre>
695
+ </div>
696
+ </div>
697
+ </div>
698
+
699
+ <div id="outline-container-sec-8" class="outline-2">
700
+ <h2 id="sec-8"><span class="section-number-2">8</span> 正規表現</h2>
701
+ <div class="outline-text-2" id="text-8">
702
+ </div><div id="outline-container-sec-8-1" class="outline-3">
703
+ <h3 id="sec-8-1"><span class="section-number-3">8.1</span> パターンとマッチング</h3>
704
+ <div class="outline-text-3" id="text-8-1">
705
+ <div class="org-src-container">
706
+
707
+ <pre class="src src-ruby"></pre>
708
+ </div>
709
+ </div>
710
+ </div>
711
+ </div>
712
+
713
+ <div id="outline-container-sec-9" class="outline-2">
714
+ <h2 id="sec-9"><span class="section-number-2">9</span> ファイルからの読み込み</h2>
715
+ <div class="outline-text-2" id="text-9">
716
+ </div><div id="outline-container-sec-9-1" class="outline-3">
717
+ <h3 id="sec-9-1"><span class="section-number-3">9.1</span> read_text.rb</h3>
718
+ <div class="outline-text-3" id="text-9-1">
719
+ <p>
720
+ コマンドラインからファイル名を受け取り、該当ファイルのテキストデータを表示するプログラム
721
+ </p>
722
+
723
+ <div class="org-src-container">
724
+
725
+ <pre class="src src-ruby">filename = ARGV[0]
726
+ text = File.read(filename)
727
+ print text
728
+ </pre>
729
+ </div>
730
+
731
+ <pre class="example">
732
+ &gt;ruby answer.rb [filename]
733
+ [text]
734
+ </pre>
735
+ </div>
736
+ </div>
737
+
738
+ <div id="outline-container-sec-9-2" class="outline-3">
739
+ <h3 id="sec-9-2"><span class="section-number-3">9.2</span> read_line.rb</h3>
740
+ <div class="outline-text-3" id="text-9-2">
741
+ <p>
742
+ コマンドラインからファイル名を受け取り、該当ファイルのテキストデータを1行ずつ表示すつプログラム
743
+ </p>
744
+
745
+ <div class="org-src-container">
746
+
747
+ <pre class="src src-ruby">filename = ARGV[0]
748
+ file = File.open(filename)
749
+ file.each_line do |line|
750
+ print line
751
+ end
752
+ </pre>
753
+ </div>
754
+
755
+ <pre class="example">
756
+ </pre>
757
+ </div>
758
+ </div>
759
+
760
+ <div id="outline-container-sec-9-3" class="outline-3">
761
+ <h3 id="sec-9-3"><span class="section-number-3">9.3</span> simple_grep.rb</h3>
762
+ <div class="outline-text-3" id="text-9-3">
763
+ <p>
764
+ 入力したテキストデータの中から、正規表現で指定した特定のパターンにマッチする行を出力するプログラム
765
+ </p>
766
+
767
+ <div class="org-src-container">
768
+
769
+ <pre class="src src-ruby">pattern = Regexp.new(ARGV[0])
770
+ filename = ARGV[1]
771
+
772
+ file = File.open(filename)
773
+ file.each_line do |line|
774
+ if pattern =~ line
775
+ print line
776
+ end
777
+ end
778
+ file.close
779
+ </pre>
780
+ </div>
781
+
782
+ <pre class="example">
783
+ &gt;ruby answer.rb [pattern] [filename]
784
+ </pre>
785
+ </div>
786
+ </div>
787
+ </div>
788
+
789
+ <div id="outline-container-sec-10" class="outline-2">
790
+ <h2 id="sec-10"><span class="section-number-2">10</span> メソッドの作成</h2>
791
+ <div class="outline-text-2" id="text-10">
792
+ </div><div id="outline-container-sec-10-1" class="outline-3">
793
+ <h3 id="sec-10-1"><span class="section-number-3">10.1</span> hello_ruby2.rb</h3>
794
+ <div class="outline-text-3" id="text-10-1">
795
+ <p>
796
+ 「Hello, Ruby.」と表示するメソッドhelloを用いて、
797
+ </p>
798
+
799
+
800
+ <div class="org-src-container">
801
+
802
+ <pre class="src src-ruby">def hello
803
+ puts "Hello, Ruby."
804
+ end
805
+
806
+ hello()
807
+ </pre>
808
+ </div>
809
+
810
+ <pre class="example">
811
+ &gt; ruby hello_ruby2.rb
812
+ Hello, Ruby.
813
+ </pre>
814
+ </div>
815
+ </div>
816
+ </div>
817
+
818
+
819
+
820
+
821
+ <div id="outline-container-sec-11" class="outline-2">
822
+ <h2 id="sec-11"><span class="section-number-2">11</span> 別のファイルを取り込む</h2>
823
+ <div class="outline-text-2" id="text-11">
824
+ </div><div id="outline-container-sec-11-1" class="outline-3">
825
+ <h3 id="sec-11-1"><span class="section-number-3">11.1</span> ディレクトリ内のファイルの取り込み</h3>
826
+ <div class="outline-text-3" id="text-11-1">
827
+ <div class="org-src-container">
828
+
829
+ <pre class="src src-ruby">def simple_grep(pattern, filename)
830
+ file = File.open(filename)
831
+ file.each_line do |line|
832
+ if pattern =~ line
833
+ print line
834
+ end
835
+ end
836
+ file.close
837
+ end
838
+ </pre>
839
+ </div>
840
+
841
+ <div class="org-src-container">
842
+
843
+ <pre class="src src-ruby">require_relative "grep"
844
+
845
+ pattern = Regexp.new(ARGV[0])
846
+ filename = ARGV[1]
847
+ simple_grep(pattern, filename)
848
+ </pre>
849
+ </div>
850
+ </div>
851
+ </div>
852
+
853
+ <div id="outline-container-sec-11-2" class="outline-3">
854
+ <h3 id="sec-11-2"><span class="section-number-3">11.2</span> Rubyの標準ライブラリ</h3>
855
+ <div class="outline-text-3" id="text-11-2">
856
+ <div class="org-src-container">
857
+
858
+ <pre class="src src-ruby">require "date"
859
+
860
+ days = Date.today - Date.new(1993, 2, 24)
861
+ puts(days.to_i)
862
+ </pre>
863
+ </div>
864
+ </div>
865
+ </div>
866
+ </div>
867
+ </div>
868
+ <div id="postamble" class="status">
869
+ <p class="author">Author: Shun Takahashi</p>
870
+ <p class="date">Created: 2018-08-04 土 06:48</p>
871
+ <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>
872
+ <p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
873
+ </div>
874
+ </body>
875
+ </html>