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
@@ -0,0 +1,10 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "open3"
3
+
4
+ RSpec.describe "ARGV-check" do
5
+ it 'given "for-read.txt", return 4' do
6
+ workshop = "#{ENV['HOME']}/ruby_learner/workshop"
7
+ stdout, stderr, status = Open3.capture3("ruby #{workshop}/lib/workplace.rb #{workshop}/lib/for-read.txt")
8
+ expect { puts stdout }.to output("このファイルはファイル読み込み用の練習ファイルです。\n\nむかしむかし、あるところに、おじいさんとおばあさんが住んでいました。\nおじいさんは山へしばかりに、おばあさんは川へせんたくに行きました。\nおばあさんが川でせんたくをしていると、ドンブラコ、ドンブラコと、大きな桃が流れてきました。\n").to_stdout
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ # section_9/part_2/answer.rb
2
+ # 9-2-file-open.rb
3
+ filename = ARGV[0]
4
+ file = File.open(filename)
5
+ file.each_line do |line|
6
+ print line
7
+ end
@@ -0,0 +1,2 @@
1
+ # -*- coding: utf-8 -*-
2
+ 1つの文字列を受け取り、該当するファイル名のテキストデータを1行ずつ読み取り、表示するプログラムを作成せよ。
@@ -0,0 +1 @@
1
+ # section_9/part_2/workplace.rb
@@ -0,0 +1,100 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16
+ RSpec.configure do |config|
17
+ # rspec-expectations config goes here. You can use an alternate
18
+ # assertion/expectation library such as wrong or the stdlib/minitest
19
+ # assertions if you prefer.
20
+ config.expect_with :rspec do |expectations|
21
+ # This option will default to `true` in RSpec 4. It makes the `description`
22
+ # and `failure_message` of custom matchers include text for helper methods
23
+ # defined using `chain`, e.g.:
24
+ # be_bigger_than(2).and_smaller_than(4).description
25
+ # # => "be bigger than 2 and smaller than 4"
26
+ # ...rather than:
27
+ # # => "be bigger than 2"
28
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
29
+ end
30
+
31
+ # rspec-mocks config goes here. You can use an alternate test double
32
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
33
+ config.mock_with :rspec do |mocks|
34
+ # Prevents you from mocking or stubbing a method that does not exist on
35
+ # a real object. This is generally recommended, and will default to
36
+ # `true` in RSpec 4.
37
+ mocks.verify_partial_doubles = true
38
+ end
39
+
40
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
41
+ # have no way to turn it off -- the option exists only for backwards
42
+ # compatibility in RSpec 3). It causes shared context metadata to be
43
+ # inherited by the metadata hash of host groups and examples, rather than
44
+ # triggering implicit auto-inclusion in groups with matching metadata.
45
+ config.shared_context_metadata_behavior = :apply_to_host_groups
46
+
47
+ # The settings below are suggested to provide a good initial experience
48
+ # with RSpec, but feel free to customize to your heart's content.
49
+ =begin
50
+ # This allows you to limit a spec run to individual examples or groups
51
+ # you care about by tagging them with `:focus` metadata. When nothing
52
+ # is tagged with `:focus`, all examples get run. RSpec also provides
53
+ # aliases for `it`, `describe`, and `context` that include `:focus`
54
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
55
+ config.filter_run_when_matching :focus
56
+
57
+ # Allows RSpec to persist some state between runs in order to support
58
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
59
+ # you configure your source control system to ignore this file.
60
+ config.example_status_persistence_file_path = "spec/examples.txt"
61
+
62
+ # Limits the available syntax to the non-monkey patched syntax that is
63
+ # recommended. For more details, see:
64
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
65
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
66
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
67
+ config.disable_monkey_patching!
68
+
69
+ # This setting enables warnings. It's recommended, but in some cases may
70
+ # be too noisy due to issues in dependencies.
71
+ config.warnings = true
72
+
73
+ # Many RSpec users commonly either run the entire suite or an individual
74
+ # file, and it's useful to allow more verbose output when running an
75
+ # individual spec file.
76
+ if config.files_to_run.one?
77
+ # Use the documentation formatter for detailed output,
78
+ # unless a formatter has already been configured
79
+ # (e.g. via a command-line flag).
80
+ config.default_formatter = "doc"
81
+ end
82
+
83
+ # Print the 10 slowest examples and example groups at the
84
+ # end of the spec run, to help surface which specs are running
85
+ # particularly slow.
86
+ config.profile_examples = 10
87
+
88
+ # Run specs in random order to surface order dependencies. If you find an
89
+ # order dependency and want to debug it, you can fix the order by providing
90
+ # the seed, which is printed after each run.
91
+ # --seed 1234
92
+ config.order = :random
93
+
94
+ # Seed global randomization in this process using the `--seed` CLI option.
95
+ # Setting this allows you to use `--seed` to deterministically reproduce
96
+ # test failures related to randomization by passing the same `--seed` value
97
+ # as the one that triggered the failure.
98
+ Kernel.srand config.seed
99
+ =end
100
+ end
@@ -0,0 +1,10 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "open3"
3
+
4
+ RSpec.describe "ARGV-check" do
5
+ it 'given "for-read.txt", return 4' do
6
+ workshop = "#{ENV['HOME']}/ruby_learner/workshop"
7
+ stdout, stderr, status = Open3.capture3("ruby #{workshop}/lib/workplace.rb #{workshop}/lib/for-read.txt")
8
+ expect { puts stdout }.to output("このファイルはファイル読み込み用の練習ファイルです。\n\nむかしむかし、あるところに、おじいさんとおばあさんが住んでいました。\nおじいさんは山へしばかりに、おばあさんは川へせんたくに行きました。\nおばあさんが川でせんたくをしていると、ドンブラコ、ドンブラコと、大きな桃が流れてきました。\n").to_stdout
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ # section_9/part_3/answer.rb
2
+ # 9-3-pattern.rb
3
+ pattern = Regexp.new(ARGV[0])
4
+ filename = ARGV[1]
5
+
6
+ file = File.open(filename)
7
+ file.each_line do |line|
8
+ if pattern =~ line
9
+ print line
10
+ end
11
+ end
12
+ file.close
@@ -0,0 +1,2 @@
1
+ # -*- coding: utf-8 -*-
2
+ 2つの文字列を受け取り、2つ目の文字列に該当するファイル名のテキストデータの中から、1つ目の文字列にマッチする行を出力するプログラムを作成せよ。
@@ -0,0 +1 @@
1
+ # section_9/part_3/workplace.rb
@@ -0,0 +1,100 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16
+ RSpec.configure do |config|
17
+ # rspec-expectations config goes here. You can use an alternate
18
+ # assertion/expectation library such as wrong or the stdlib/minitest
19
+ # assertions if you prefer.
20
+ config.expect_with :rspec do |expectations|
21
+ # This option will default to `true` in RSpec 4. It makes the `description`
22
+ # and `failure_message` of custom matchers include text for helper methods
23
+ # defined using `chain`, e.g.:
24
+ # be_bigger_than(2).and_smaller_than(4).description
25
+ # # => "be bigger than 2 and smaller than 4"
26
+ # ...rather than:
27
+ # # => "be bigger than 2"
28
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
29
+ end
30
+
31
+ # rspec-mocks config goes here. You can use an alternate test double
32
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
33
+ config.mock_with :rspec do |mocks|
34
+ # Prevents you from mocking or stubbing a method that does not exist on
35
+ # a real object. This is generally recommended, and will default to
36
+ # `true` in RSpec 4.
37
+ mocks.verify_partial_doubles = true
38
+ end
39
+
40
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
41
+ # have no way to turn it off -- the option exists only for backwards
42
+ # compatibility in RSpec 3). It causes shared context metadata to be
43
+ # inherited by the metadata hash of host groups and examples, rather than
44
+ # triggering implicit auto-inclusion in groups with matching metadata.
45
+ config.shared_context_metadata_behavior = :apply_to_host_groups
46
+
47
+ # The settings below are suggested to provide a good initial experience
48
+ # with RSpec, but feel free to customize to your heart's content.
49
+ =begin
50
+ # This allows you to limit a spec run to individual examples or groups
51
+ # you care about by tagging them with `:focus` metadata. When nothing
52
+ # is tagged with `:focus`, all examples get run. RSpec also provides
53
+ # aliases for `it`, `describe`, and `context` that include `:focus`
54
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
55
+ config.filter_run_when_matching :focus
56
+
57
+ # Allows RSpec to persist some state between runs in order to support
58
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
59
+ # you configure your source control system to ignore this file.
60
+ config.example_status_persistence_file_path = "spec/examples.txt"
61
+
62
+ # Limits the available syntax to the non-monkey patched syntax that is
63
+ # recommended. For more details, see:
64
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
65
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
66
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
67
+ config.disable_monkey_patching!
68
+
69
+ # This setting enables warnings. It's recommended, but in some cases may
70
+ # be too noisy due to issues in dependencies.
71
+ config.warnings = true
72
+
73
+ # Many RSpec users commonly either run the entire suite or an individual
74
+ # file, and it's useful to allow more verbose output when running an
75
+ # individual spec file.
76
+ if config.files_to_run.one?
77
+ # Use the documentation formatter for detailed output,
78
+ # unless a formatter has already been configured
79
+ # (e.g. via a command-line flag).
80
+ config.default_formatter = "doc"
81
+ end
82
+
83
+ # Print the 10 slowest examples and example groups at the
84
+ # end of the spec run, to help surface which specs are running
85
+ # particularly slow.
86
+ config.profile_examples = 10
87
+
88
+ # Run specs in random order to surface order dependencies. If you find an
89
+ # order dependency and want to debug it, you can fix the order by providing
90
+ # the seed, which is printed after each run.
91
+ # --seed 1234
92
+ config.order = :random
93
+
94
+ # Seed global randomization in this process using the `--seed` CLI option.
95
+ # Setting this allows you to use `--seed` to deterministically reproduce
96
+ # test failures related to randomization by passing the same `--seed` value
97
+ # as the one that triggered the failure.
98
+ Kernel.srand config.seed
99
+ =end
100
+ end
@@ -0,0 +1,10 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "open3"
3
+
4
+ RSpec.describe "ARGV-check" do
5
+ it 'given 3 "for-read.txt", return 4' do
6
+ workshop = "#{ENV['HOME']}/ruby_learner/workshop"
7
+ stdout, stderr, status = Open3.capture3("ruby #{workshop}/lib/workplace.rb 'ドンブラコ' #{workshop}/lib/for-read.txt")
8
+ expect { puts stdout }.to output("おばあさんが川でせんたくをしていると、ドンブラコ、ドンブラコと、大きな桃が流れてきました。\n").to_stdout
9
+ end
10
+ end
@@ -137,3 +137,12 @@ answer/2_1.rb:1:1: C: Style/Encoding: Unnecessary utf-8 encoding comment.
137
137
 
138
138
  -ARGVで受け取った文字列を数値に変換して表示するプログラム
139
139
  -正規表現を上手い具合に問題に落とし込みたい
140
+
141
+ ** 8/13
142
+
143
+ 問題文作成
144
+
145
+ 応用問題としてrakeを使うって話があったはず
146
+ たのしいRuby掲載のrake関係の頁は正直本を読み込まないと理解できないレベルのコードが書いてある
147
+
148
+ どうしましょ
@@ -0,0 +1,139 @@
1
+
2
+ * 卒業研究
3
+
4
+ ** Thema
5
+ editor_learner を基にした Ruby 習熟プログラム ruby_learner(仮) 開発
6
+
7
+ CUI ベースで動作するプログラム ruby の基本的な動作、規則、記法などを習得
8
+
9
+ ** 研究方針?
10
+ editor_learner の目的は emacs 上でのtype操作の習熟
11
+ ruby_learner(仮)の目的は ruby の習熟->一週間でrubyが扱える!
12
+
13
+ # 「ruby の習熟」の定義?
14
+ # 何を以って「ruby を習得した」とみなす?
15
+
16
+ たのしいRuby第5版を’実行しながら’読み込み、思ったことを全て羅列
17
+
18
+
19
+
20
+ ** 評価形式
21
+ # editor_learner は時間計測により習熟度を評価
22
+ # ruby_learner(仮)の評価形式は?
23
+
24
+
25
+
26
+ 2018/7/25
27
+
28
+ ** 結局何をするのか
29
+
30
+ Ruby習熟のための問題作成。
31
+
32
+ 問題形式
33
+
34
+ ・出題に対する回答となるプログラムの記述
35
+
36
+
37
+ *** 大津君との連携
38
+
39
+ 私のやること
40
+
41
+ ・Ruby習熟のための問題作成
42
+ ・出題システム構成
43
+
44
+ 大津君のやること
45
+
46
+ ・”問題”の添削システム構成
47
+ ・rspecのtestを作成(red-green-refactaringのred-greenの部分)
48
+ ・abc_size_check機能(green-refactaringの部分)の実装
49
+
50
+ ** ゼミ
51
+
52
+ githubでRuby_learnerのプロジェクトを立ち上げ
53
+
54
+ 以後進捗等適宜
55
+
56
+ 丸写しのテキストではなく、
57
+ レジュメにすること。じぶんの「独自の」まとめを書く
58
+
59
+ org-html-themes
60
+
61
+
62
+ Ruby勉強ドリルを作るんだよ
63
+
64
+
65
+
66
+ **
67
+ コードはテスト
68
+
69
+
70
+ ruby_learner 起動方法
71
+ 1. rake build
72
+ 2. rake install:local
73
+ 3. ruby_learner [COMMAND]
74
+
75
+
76
+ ** 8/1 ゼミ
77
+
78
+ 「たのしいRuby1章の内容を完璧にできるプログラムの完成」
79
+
80
+ 見栄えの良いドリル(見辛い参考書で勉強する奴はいない
81
+
82
+ たのしいRUbyはなぜ見栄えがいいのか?
83
+ (少なくとも自分は読んでそう感じたはずで、ならばその理由があるはず
84
+
85
+
86
+ 文章校正
87
+
88
+ rubocop
89
+
90
+ それができてから次のことー>応用、発展の習熟
91
+
92
+
93
+ 言語の修得
94
+ ・テキスト
95
+ ・リファレンス・マニュアル
96
+ ー文法、関数の使い方等(必要な時に参照
97
+ ・逆引き
98
+ ー何かをしたいー>どう書くか
99
+ ・問題集
100
+
101
+ たのしいRuby第5版に、「Rake」「正規表現」を用いた応用が含まれるか?
102
+ 含まれていないなら、第3版23章を参考にする
103
+
104
+
105
+ ** 8/4
106
+
107
+ -番号はたのしいRuby準拠の仮置きなので、あとで入れ替えます
108
+
109
+ -8_1 8_2は2_1より前に持ってくるかも
110
+
111
+ -2_1.rbのrubocopの添削について
112
+
113
+ #+begin
114
+ > rubocop answer/2_1.rb
115
+ Inspecting 1 file
116
+ C
117
+
118
+ Offenses:
119
+
120
+ answer/2_1.rb:1:1: C: Style/Encoding: Unnecessary utf-8 encoding comment.
121
+ # -*- coding: utf-8 -*-
122
+ ^^^^^^^^^^^^^^^^^^^^^^^
123
+
124
+ 1 file inspected, 1 offense detected
125
+ #+end
126
+
127
+ 文字コードの記述、rubocopは必要無いと言うけどemacsだと勝手に記述されてしまう
128
+ 解答例のコードに日本語入れない方が良い?
129
+
130
+ -4_1.rbと4_2.rbは順番入れ替えます
131
+
132
+ -8_2.rb 計算するためにint型に変換する必要あったので、別に変数用意して出力
133
+
134
+ -9_3.rb else使わないならif使わない方がいいって意味なんだろうけど、代わりに何使うのか分からない
135
+
136
+ *** 他入れておきたい問題
137
+
138
+ -ARGVで受け取った文字列を数値に変換して表示するプログラム
139
+ -正規表現を上手い具合に問題に落とし込みたい
@@ -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 06:48 -->
7
+ <!-- 2018-08-14 17:07 -->
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" />
@@ -195,7 +195,6 @@ for the JavaScript code in this tag.
195
195
  <li><a href="#sec-1-1">1.1. helloruby.rb</a></li>
196
196
  <li><a href="#sec-1-2">1.2. helloruby_2.rb</a></li>
197
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
198
  </ul>
200
199
  </li>
201
200
  <li><a href="#sec-2">2. コマンドラインからのデータの入力</a>
@@ -211,8 +210,7 @@ for the JavaScript code in this tag.
211
210
  </li>
212
211
  <li><a href="#sec-4">4. 条件判断</a>
213
212
  <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>
213
+ <li><a href="#sec-4-1">4.1. greater_smaller_else.rb</a></li>
216
214
  </ul>
217
215
  </li>
218
216
  <li><a href="#sec-5">5. 繰り返し</a>
@@ -250,6 +248,7 @@ for the JavaScript code in this tag.
250
248
  <li><a href="#sec-10">10. メソッドの作成</a>
251
249
  <ul>
252
250
  <li><a href="#sec-10-1">10.1. hello_ruby2.rb</a></li>
251
+ <li><a href="#sec-10-2">10.2. hello_ruby3.rb</a></li>
253
252
  </ul>
254
253
  </li>
255
254
  <li><a href="#sec-11">11. 別のファイルを取り込む</a>
@@ -270,16 +269,17 @@ for the JavaScript code in this tag.
270
269
  <h3 id="sec-1-1"><span class="section-number-3">1.1</span> helloruby.rb</h3>
271
270
  <div class="outline-text-3" id="text-1-1">
272
271
  <p>
273
- 「Hello, Ruby.」という文字列を出力するプログラムを作成せよ
272
+ 「Hello, Ruby.」という文字列を表示するプログラムを作成せよ。
274
273
  </p>
275
274
 
276
275
  <div class="org-src-container">
277
276
 
278
- <pre class="src src-ruby">print('Hello, Ruby.\n')
277
+ <pre class="src src-ruby">print 'Hello, Ruby.\n'
279
278
  </pre>
280
279
  </div>
281
280
 
282
281
  <pre class="example">
282
+ &gt; answer.rb
283
283
  Hello, Ruby.
284
284
  </pre>
285
285
  </div>
@@ -289,18 +289,18 @@ Hello, Ruby.
289
289
  <h3 id="sec-1-2"><span class="section-number-3">1.2</span> helloruby_2.rb</h3>
290
290
  <div class="outline-text-3" id="text-1-2">
291
291
  <p>
292
- 「Hello, "Ruby".」という文字列を出力するプログラムを作成せよ
292
+ 「Hello, "Ruby".」という文字列を表示するプログラムを作成せよ。
293
293
  </p>
294
294
 
295
295
  <div class="org-src-container">
296
296
 
297
- <pre class="src src-ruby">print("Hello, \"Ruby\".\n")
297
+ <pre class="src src-ruby">print Hello, \"Ruby\".\n"
298
298
  </pre>
299
299
  </div>
300
300
 
301
301
  <pre class="example">
302
- &gt; helloruby_2.rb
303
- Hello,"Ruby".
302
+ &gt; answer.rb
303
+ Hello, "Ruby".
304
304
  </pre>
305
305
  </div>
306
306
  </div>
@@ -309,7 +309,7 @@ Hello,"Ruby".
309
309
  <h3 id="sec-1-3"><span class="section-number-3">1.3</span> p_method.rb</h3>
310
310
  <div class="outline-text-3" id="text-1-3">
311
311
  <p>
312
- 「"Hello,\n\tRuby."」という文字列を出力するプログラムを作成せよ
312
+ 「"Hello,\n\tRuby."」という文字列を表示するプログラムを作成せよ。
313
313
  </p>
314
314
 
315
315
  <div class="org-src-container">
@@ -317,14 +317,11 @@ Hello,"Ruby".
317
317
  <pre class="src src-ruby">p "Hello,\n\tRuby."
318
318
  </pre>
319
319
  </div>
320
- </div>
321
- </div>
322
-
323
-
324
320
 
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">
321
+ <pre class="example">
322
+ &gt; answer.rb
323
+ "Hello,\n\tRuby."
324
+ </pre>
328
325
  </div>
329
326
  </div>
330
327
  </div>
@@ -336,39 +333,35 @@ Hello,"Ruby".
336
333
  <h3 id="sec-2-1"><span class="section-number-3">2.1</span> print_argv.rb</h3>
337
334
  <div class="outline-text-3" id="text-2-1">
338
335
  <p>
339
- コマンドラインから引数を5つ入力として受け取り、出力するプログラム
336
+ コマンドラインから5つの引数を受け取り、受け取った順に表示するプログラムを作成せよ。
340
337
  </p>
341
338
 
342
339
  <div class="org-src-container">
343
340
 
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]}"
341
+ <pre class="src src-ruby">puts ARGV[0]
342
+ puts ARGV[1]
343
+ puts ARGV[2]
344
+ puts ARGV[3]
345
+ puts ARGV[4]
350
346
  </pre>
351
347
  </div>
352
348
 
353
349
  <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
350
+ &gt; ruby answer.rb 1st 2nd 3rd 4th 5th
351
+ 1st
352
+ 2nd
353
+ 3rd
354
+ 4th
355
+ 5th
361
356
  </pre>
362
357
  </div>
363
358
  </div>
364
359
 
365
-
366
-
367
360
  <div id="outline-container-sec-2-2" class="outline-3">
368
361
  <h3 id="sec-2-2"><span class="section-number-3">2.2</span> arg_arith.rb</h3>
369
362
  <div class="outline-text-3" id="text-2-2">
370
363
  <p>
371
- コマンドラインから数値を2つ受け取り、和、差、積、商を表示するプログラム
364
+ コマンドラインから数値を2つ受け取り、その和、差、積、商を表示するプログラムを作成せよ。
372
365
  </p>
373
366
 
374
367
  <div class="org-src-container">
@@ -376,10 +369,15 @@ puts "5番目の引数: #{ARGV[4]}"
376
369
  <pre class="src src-ruby">num0 = ARGV[0].to_i
377
370
  num1 = ARGV[1].to_i
378
371
 
379
- puts "#{num0 + num1}"
380
- puts "#{num0 - num1}"
381
- puts "#{num0 * num1}"
382
- puts "#{num0 / num1}"
372
+ sum = num0 + num1
373
+ dif = num0 - num1
374
+ pro = num0 * num1
375
+ quo = num0 / num1
376
+
377
+ puts sum
378
+ puts dif
379
+ puts pro
380
+ puts quo
383
381
  </pre>
384
382
  </div>
385
383
 
@@ -401,7 +399,7 @@ puts "#{num0 / num1}"
401
399
  <h3 id="sec-3-1"><span class="section-number-3">3.1</span> area_volume.rb</h3>
402
400
  <div class="outline-text-3" id="text-3-1">
403
401
  <p>
404
- 3つの数値x、y、zを受け取り、縦x、横y、高さzの直方体の表面積と体積を求めるプログラム
402
+ 3つの数値をx、y、zとして受け取り、縦x、横y、高さzの直方体の表面積と体積を求め、表示するプログラムを作成せよ。
405
403
  </p>
406
404
 
407
405
  <div class="org-src-container">
@@ -410,16 +408,16 @@ puts "#{num0 / num1}"
410
408
  y = ARGV[1].to_i
411
409
  z = ARGV[2].to_i
412
410
 
413
- area = (x*y + y*z + z*x) * 2
411
+ area = (x * y + y * z + z * x) * 2
414
412
  volume = x * y * z
415
413
 
416
- print "表面積=", area, "\n"
417
- print "体積=" volume, "\n"
414
+ print '表面積=', area, "\n"
415
+ print '体積=' volume, "\n"
418
416
  </pre>
419
417
  </div>
420
418
 
421
419
  <pre class="example">
422
- &gt; ruby area_volume.rb 10 20 30
420
+ &gt; ruby answer.rb 10 20 30
423
421
  表面積=2200
424
422
  体積=6000
425
423
  </pre>
@@ -431,40 +429,10 @@ print "体積=" volume, "\n"
431
429
  <h2 id="sec-4"><span class="section-number-2">4</span> 条件判断</h2>
432
430
  <div class="outline-text-2" id="text-4">
433
431
  </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>
432
+ <h3 id="sec-4-1"><span class="section-number-3">4.1</span> greater_smaller_else.rb</h3>
435
433
  <div class="outline-text-3" id="text-4-1">
436
434
  <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を用いて実行するプログラム
435
+ 1つの数値を受け取り、それが10より大きければ「greater」小さければ「smaller」と表示するプログラムを作成せよ。
468
436
  </p>
469
437
 
470
438
  <div class="org-src-container">
@@ -475,14 +443,15 @@ if a &gt;= 10
475
443
  print "greater\n"
476
444
  else
477
445
  print "smaller\n"
446
+ end
478
447
  </pre>
479
448
  </div>
480
449
 
481
450
  <pre class="example">
482
- &gt;ruby greater_smaller_else.rb 20
451
+ &gt;ruby answer.rb 20
483
452
  greater
484
453
 
485
- &gt;ruby greater_smaller_else.rb 5
454
+ &gt;ruby answer.rb 5
486
455
  smaller
487
456
  </pre>
488
457
  </div>
@@ -496,7 +465,7 @@ smaller
496
465
  <h3 id="sec-5-1"><span class="section-number-3">5.1</span> 1_to_n.rb</h3>
497
466
  <div class="outline-text-3" id="text-5-1">
498
467
  <p>
499
- 入力された1つの数値nを引数として受け取り、1からnまでの数を順番に表示するプログラムを作成せよ
468
+ 1つの数値をnとして受け取り、1からnまでの数を順番に表示するプログラムを作成せよ。
500
469
  </p>
501
470
 
502
471
  <div class="org-src-container">
@@ -505,13 +474,13 @@ smaller
505
474
  i = 1
506
475
  while i &lt;= n
507
476
  print i, "\n"
508
- i = i + 1
477
+ i += 1
509
478
  end
510
479
  </pre>
511
480
  </div>
512
481
 
513
482
  <pre class="example">
514
- &gt; ruby 1_to_n.rb 5
483
+ &gt; ruby answer.rb 5
515
484
  1
516
485
  2
517
486
  3
@@ -525,22 +494,30 @@ end
525
494
  <h3 id="sec-5-2"><span class="section-number-3">5.2</span> five_times.rb</h3>
526
495
  <div class="outline-text-3" id="text-5-2">
527
496
  <p>
528
- 「All work and no play makes Jack a dull boy.」と5行表示するプログラム
497
+ 「All work and no play makes Jack a dull boy.」と5行表示するプログラムを作成せよ。
529
498
  </p>
530
499
 
531
500
  <div class="org-src-container">
532
501
 
533
502
  <pre class="src src-ruby">5.times do
534
- print "All work and no play makes Jack a dull boy."
503
+ print "All work and no play makes Jack a dull boy.\n"
535
504
  end
536
505
  </pre>
537
506
  </div>
507
+
508
+ <pre class="example">
509
+ &gt; answer.rb
510
+ All work and no play makes Jack a dull boy.
511
+ All work and no play makes Jack a dull boy.
512
+ All work and no play makes Jack a dull boy.
513
+ All work and no play makes Jack a dull boy.
514
+ All work and no play makes Jack a dull boy.
515
+ </pre>
538
516
  </div>
539
517
  </div>
540
518
  </div>
541
519
 
542
520
 
543
-
544
521
  <div id="outline-container-sec-6" class="outline-2">
545
522
  <h2 id="sec-6"><span class="section-number-2">6</span> 配列</h2>
546
523
  <div class="outline-text-2" id="text-6">
@@ -548,38 +525,40 @@ end
548
525
  <h3 id="sec-6-1"><span class="section-number-3">6.1</span> 配列からオブジェクトを取り出す</h3>
549
526
  <div class="outline-text-3" id="text-6-1">
550
527
  <p>
551
- 配列のn番目の要素を取り出し、表示するプログラム
528
+ 1つの数値をnとして受け取り、配列のn番目の要素を取り出し、表示するプログラムを作成せよ。ただし、配列はプログラム内で定義し、配列には数値が入るものとする。
552
529
  </p>
553
530
 
554
531
  <div class="org-src-container">
555
532
 
556
- <pre class="src src-ruby">names = ["小林", "林", "高野", "森岡"]
533
+ <pre class="src src-ruby">nums = [3, 1, 4, 1, 5]
557
534
 
558
- print names[ARGV[0]]
535
+ print nums[ARGV[0].to_i]
559
536
  </pre>
560
537
  </div>
561
538
 
562
- <div class="org-src-container">
539
+ <pre class="example">
540
+ &gt; ruby answer.rb 0
541
+ 3
563
542
 
564
- <pre class="src src-ruby">&gt;ruby answer.rb 0
565
- 小林
543
+ &gt; ruby answer.rb 3
544
+ 1
566
545
  </pre>
567
546
  </div>
568
547
  </div>
569
- </div>
570
548
 
571
549
  <div id="outline-container-sec-6-2" class="outline-3">
572
550
  <h3 id="sec-6-2"><span class="section-number-3">6.2</span> 配列にオブジェクトを格納する</h3>
573
551
  <div class="outline-text-3" id="text-6-2">
574
552
  <p>
575
- 配列の先頭の要素をコマンドラインに入力した要素に変更するプログラム
553
+ 配列の先頭の要素をコマンドラインに入力した要素に変更するプログラムを作成せよ。
554
+ ただし、配列はプログラム内で定義し、配列には数値が入るものとする。
576
555
  </p>
577
556
 
578
557
  <div class="org-src-container">
579
558
 
580
- <pre class="src src-ruby">nums = [1, 2, 3]
559
+ <pre class="src src-ruby">nums = [3, 1, 4, 1, 5]
581
560
 
582
- nums[0] = ARGV[0]
561
+ nums[0] = ARGV[0].to_i
583
562
 
584
563
  print nums
585
564
  </pre>
@@ -588,7 +567,7 @@ print nums
588
567
 
589
568
  <pre class="example">
590
569
  &gt; ruby answer.rb 5
591
- [5, 2, 3]
570
+ [5, 1, 4, 1, 5]
592
571
  </pre>
593
572
  </div>
594
573
  </div>
@@ -597,18 +576,25 @@ print nums
597
576
  <h3 id="sec-6-3"><span class="section-number-3">6.3</span> 配列の大きさ</h3>
598
577
  <div class="outline-text-3" id="text-6-3">
599
578
  <p>
600
- 配列を表示し、その配列の大きさも表示するプログラムを作成せよ
579
+ 配列を表示し、その配列の大きさも表示するプログラムを作成せよ。
580
+ ただし、配列はプログラム内で定義すること。
601
581
  </p>
602
582
 
603
583
  <div class="org-src-container">
604
584
 
605
- <pre class="src src-ruby">names =
585
+ <pre class="src src-ruby">nums = [3, 1, 4, 1, 5]
606
586
 
607
- print names, "\n"
587
+ print nums, "\n"
608
588
 
609
- print names.size
589
+ print nums.size, "\n"
610
590
  </pre>
611
591
  </div>
592
+
593
+ <pre class="example">
594
+ &gt; ruby answer.rb
595
+ [3, 1, 4, 1, 5]
596
+ 5
597
+ </pre>
612
598
  </div>
613
599
  </div>
614
600
 
@@ -616,16 +602,17 @@ print names.size
616
602
  <h3 id="sec-6-4"><span class="section-number-3">6.4</span> 配列と繰り返し</h3>
617
603
  <div class="outline-text-3" id="text-6-4">
618
604
  <p>
619
- 配列全体を表示してから、配列の要素を順に表示するプログラム
605
+ 配列全体を表示してから、配列の要素を順に表示するプログラムを作成せよ。
606
+ ただし、配列はプログラム内で定義すること。
620
607
  </p>
621
608
 
622
609
  <div class="org-src-container">
623
610
 
624
- <pre class="src src-ruby">names = ["小林", "林", "高野", "森岡"]
611
+ <pre class="src src-ruby">nums = [3, 1, 4, 1, 5]
625
612
 
626
- print names, "\n"
613
+ print nums, "\n"
627
614
 
628
- names.each do |n|
615
+ nums.each do |n|
629
616
  puts n
630
617
  end
631
618
  </pre>
@@ -633,11 +620,12 @@ end
633
620
 
634
621
  <pre class="example">
635
622
  &gt; ruby answer.rb
636
- ["小林", "林", "高野", "森岡"]
637
- 小林
638
-
639
- 高野
640
- 森岡
623
+ [3, 1, 4, 1, 5]
624
+ 3
625
+ 1
626
+ 4
627
+ 1
628
+ 5
641
629
  </pre>
642
630
  </div>
643
631
  </div>
@@ -650,7 +638,7 @@ end
650
638
  <h3 id="sec-7-1"><span class="section-number-3">7.1</span> シンボル</h3>
651
639
  <div class="outline-text-3" id="text-7-1">
652
640
  <p>
653
- コマンドラインから文字列を受け取り、シンボルに変換して表示するプログラム
641
+ 1つの文字列を受け取り、シンボルに変換して表示するプログラムを作成せよ。
654
642
  </p>
655
643
 
656
644
  <div class="org-src-container">
@@ -672,12 +660,12 @@ p n.to_sym
672
660
  <h3 id="sec-7-2"><span class="section-number-3">7.2</span> ハッシュの操作</h3>
673
661
  <div class="outline-text-3" id="text-7-2">
674
662
  <p>
675
- :name, :furiganaというそれぞれのキーに"高橋", "タカハシ"というオブジェクトが格納されているハッシュを表示、さらに:telというキーに"000-1234-5678"を格納して再度表示するプログラム
663
+ :name, :furigana というそれぞれのキーに"高橋", "タカハシ"というオブジェクトが格納されているハッシュを作成、表示し、さらに:tel というキーに"000-1234-5678"を格納して再度表示するプログラムを作成せよ。
676
664
  </p>
677
665
 
678
666
  <div class="org-src-container">
679
667
 
680
- <pre class="src src-ruby">address = {name: "高橋", furigana: "タカハシ"}
668
+ <pre class="src src-ruby">address = { name: "高橋", furigana: "タカハシ" }
681
669
 
682
670
  puts address
683
671
 
@@ -702,10 +690,29 @@ puts address
702
690
  </div><div id="outline-container-sec-8-1" class="outline-3">
703
691
  <h3 id="sec-8-1"><span class="section-number-3">8.1</span> パターンとマッチング</h3>
704
692
  <div class="outline-text-3" id="text-8-1">
693
+ <p>
694
+ 1つの文字列を受け取り、それが「Hello, Ruby」とマッチするなら「match.」マッチしないなら「not match.」と表示するプログラムを作成せよ。
695
+ </p>
696
+
705
697
  <div class="org-src-container">
706
698
 
707
- <pre class="src src-ruby"></pre>
699
+ <pre class="src src-ruby">n = /#{ARGV[0]}/
700
+
701
+ if n =~ "Hello, Ruby."
702
+ print "match.\n"
703
+ else
704
+ print "not match\n"
705
+ end
706
+ </pre>
708
707
  </div>
708
+
709
+ <pre class="example">
710
+ &gt; ruby answer.rb Ruby
711
+ match.
712
+
713
+ &gt; ruby answer.rb RUBY
714
+ not match.
715
+ </pre>
709
716
  </div>
710
717
  </div>
711
718
  </div>
@@ -717,7 +724,7 @@ puts address
717
724
  <h3 id="sec-9-1"><span class="section-number-3">9.1</span> read_text.rb</h3>
718
725
  <div class="outline-text-3" id="text-9-1">
719
726
  <p>
720
- コマンドラインからファイル名を受け取り、該当ファイルのテキストデータを表示するプログラム
727
+ 1つの文字列を受け取り、該当するファイル名のテキストデータを表示するプログラムを作成せよ。
721
728
  </p>
722
729
 
723
730
  <div class="org-src-container">
@@ -739,7 +746,7 @@ print text
739
746
  <h3 id="sec-9-2"><span class="section-number-3">9.2</span> read_line.rb</h3>
740
747
  <div class="outline-text-3" id="text-9-2">
741
748
  <p>
742
- コマンドラインからファイル名を受け取り、該当ファイルのテキストデータを1行ずつ表示すつプログラム
749
+ 1つの文字列を受け取り、該当するファイル名のテキストデータを1行ずつ読み取り、表示するプログラムを作成せよ。
743
750
  </p>
744
751
 
745
752
  <div class="org-src-container">
@@ -761,7 +768,7 @@ end
761
768
  <h3 id="sec-9-3"><span class="section-number-3">9.3</span> simple_grep.rb</h3>
762
769
  <div class="outline-text-3" id="text-9-3">
763
770
  <p>
764
- 入力したテキストデータの中から、正規表現で指定した特定のパターンにマッチする行を出力するプログラム
771
+ 2つの文字列を受け取り、2つ目の文字列に該当するファイル名のテキストデータの中から、1つ目の文字列にマッチする行を出力するプログラムを作成せよ。
765
772
  </p>
766
773
 
767
774
  <div class="org-src-container">
@@ -793,81 +800,128 @@ file.close
793
800
  <h3 id="sec-10-1"><span class="section-number-3">10.1</span> hello_ruby2.rb</h3>
794
801
  <div class="outline-text-3" id="text-10-1">
795
802
  <p>
796
- 「Hello, Ruby.」と表示するメソッドhelloを用いて、
803
+ 「Hello, Ruby.」と表示するメソッドhelloを用いて、「Hello, Ruby.」と表示するプログラムを作成せよ。
797
804
  </p>
798
805
 
799
-
800
806
  <div class="org-src-container">
801
807
 
802
808
  <pre class="src src-ruby">def hello
803
- puts "Hello, Ruby."
809
+ puts 'Hello, Ruby.'
804
810
  end
805
811
 
806
- hello()
812
+ hello
807
813
  </pre>
808
814
  </div>
809
815
 
810
816
  <pre class="example">
811
- &gt; ruby hello_ruby2.rb
817
+ &gt; ruby answer.rb
812
818
  Hello, Ruby.
813
819
  </pre>
814
820
  </div>
815
821
  </div>
816
- </div>
817
822
 
823
+ <div id="outline-container-sec-10-2" class="outline-3">
824
+ <h3 id="sec-10-2"><span class="section-number-3">10.2</span> hello_ruby3.rb</h3>
825
+ <div class="outline-text-3" id="text-10-2">
826
+ <p>
827
+ 1つの文字列を受け取り、「Hello, [受け取った文字列].」と表示するメソッドhelloを作成し、
828
+ 2つの文字列を受け取り、「Hello, [受け取った文字列].」と2行表示するプログラムを作成せよ。
829
+ </p>
818
830
 
831
+ <div class="org-src-container">
819
832
 
833
+ <pre class="src src-ruby">def hello(name)
834
+ print 'Hello, ', name, ".\n"
835
+ end
820
836
 
837
+ hello(ARGV[0])
838
+ hello(ARGV[1])
839
+ </pre>
840
+ </div>
841
+
842
+ <pre class="example">
843
+ &gt; ruby answer.rb Ruby Takahashi
844
+ Hello, Ruby.
845
+ Hello, Takahashi.
846
+ </pre>
847
+ </div>
848
+ </div>
849
+ </div>
821
850
  <div id="outline-container-sec-11" class="outline-2">
822
851
  <h2 id="sec-11"><span class="section-number-2">11</span> 別のファイルを取り込む</h2>
823
852
  <div class="outline-text-2" id="text-11">
824
853
  </div><div id="outline-container-sec-11-1" class="outline-3">
825
854
  <h3 id="sec-11-1"><span class="section-number-3">11.1</span> ディレクトリ内のファイルの取り込み</h3>
826
855
  <div class="outline-text-3" id="text-11-1">
856
+ <p>
857
+ 1つの文字列を受け取り、「Hello, [受け取った文字列].」と表示するメソッドhelloが書かれたプログラムhello.rbがある。
858
+ </p>
859
+
860
+ <p>
861
+ このプログラムを取り込んで、1つの文字列を受け取り、「Hello, [受け取った文字列].」と表示するプログラムを作成せよ。
862
+ </p>
863
+
864
+
865
+ <ul class="org-ul">
866
+ <li>hello.rb
867
+ </li>
868
+ </ul>
827
869
  <div class="org-src-container">
828
870
 
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
871
+ <pre class="src src-ruby">def hello(name)
872
+ print 'Hello, ', name, "\n"
837
873
  end
838
874
  </pre>
839
875
  </div>
840
876
 
841
877
  <div class="org-src-container">
842
878
 
843
- <pre class="src src-ruby">require_relative "grep"
879
+ <pre class="src src-ruby">require_relative "hello"
844
880
 
845
- pattern = Regexp.new(ARGV[0])
846
- filename = ARGV[1]
847
- simple_grep(pattern, filename)
881
+ name = ARGV[0]
882
+
883
+ hello(name)
848
884
  </pre>
849
885
  </div>
886
+
887
+ <pre class="example">
888
+ &gt; answer.rb Ruby
889
+ Hello, Ruby.
890
+ </pre>
850
891
  </div>
851
892
  </div>
852
893
 
853
894
  <div id="outline-container-sec-11-2" class="outline-3">
854
895
  <h3 id="sec-11-2"><span class="section-number-3">11.2</span> Rubyの標準ライブラリ</h3>
855
896
  <div class="outline-text-3" id="text-11-2">
897
+ <p>
898
+ Rubyの標準ライブラリ「date」を用いて、Rubyが誕生した1993年2月24日から、今日までの日数を表示するプログラムを作成せよ。
899
+ </p>
900
+
856
901
  <div class="org-src-container">
857
902
 
858
903
  <pre class="src src-ruby">require "date"
859
904
 
860
905
  days = Date.today - Date.new(1993, 2, 24)
861
- puts(days.to_i)
906
+ puts days.to_i
862
907
  </pre>
863
908
  </div>
909
+
910
+ <pre class="example">
911
+ &gt; ruby answer.rb
912
+ 9302
913
+ </pre>
914
+ <ul class="org-ul">
915
+ <li>2018/8/14時点
916
+ </li>
917
+ </ul>
864
918
  </div>
865
919
  </div>
866
920
  </div>
867
921
  </div>
868
922
  <div id="postamble" class="status">
869
923
  <p class="author">Author: Shun Takahashi</p>
870
- <p class="date">Created: 2018-08-04 06:48</p>
924
+ <p class="date">Created: 2018-08-14 17:07</p>
871
925
  <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
926
  <p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
873
927
  </div>