ruby_learner 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/contents/questions/sequential_check/section_10/part_1/lib/sentence.org +20 -1
- data/contents/questions/sequential_check/section_10/part_1/lib/workplace.rb +1 -1
- data/contents/questions/sequential_check/section_10/part_2/lib/answer.rb +8 -4
- data/contents/questions/sequential_check/section_10/part_2/lib/sentence.org +59 -10
- data/contents/questions/sequential_check/section_10/part_2/lib/workplace.rb +1 -1
- data/contents/questions/sequential_check/section_10/part_2/spec/workplace_spec.rb +2 -2
- data/contents/questions/sequential_check/section_10/part_3/lib/answer.rb +7 -10
- data/contents/questions/sequential_check/section_10/part_3/lib/sentence.org +57 -4
- data/contents/questions/sequential_check/section_10/part_3/lib/workplace.rb +1 -1
- data/contents/questions/sequential_check/section_10/part_3/spec/workplace_spec.rb +2 -2
- data/contents/questions/sequential_check/section_11/part_1/lib/answer.rb +1 -1
- data/contents/questions/sequential_check/section_11/part_1/lib/sentence.org +20 -7
- data/contents/questions/sequential_check/section_11/part_1/spec/workplace_spec.rb +16 -4
- data/contents/questions/sequential_check/section_11/part_2/lib/sentence.org +23 -4
- data/contents/questions/sequential_check/section_11/part_3/lib/answer.rb +7 -0
- data/contents/questions/sequential_check/section_11/part_3/lib/sentence.org +26 -0
- data/contents/questions/sequential_check/section_11/part_3/lib/workplace.rb +1 -0
- data/contents/questions/sequential_check/section_11/part_3/spec/spec_helper.rb +100 -0
- data/contents/questions/sequential_check/section_11/part_3/spec/workplace_spec.rb +28 -0
- data/lib/ruby_learner/sequential_main.rb +2 -2
- data/lib/ruby_learner/version.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 807588a1cb4cdcd7635b6655c2741ded318c1f06
|
4
|
+
data.tar.gz: ea243e792dd9c150a24ba183ad4d93dbbceae6f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79a4b157d87ee46376788f5066689086c13e35d7bf409d0f84fed6c5034841b6b1f0567126a34c4f55a7f2cff7af2ff995391bce4246349c393b32822691e0c3
|
7
|
+
data.tar.gz: 56c2d521d0c194e235f93e526f7cbb64e81993c9ecd40db3267fcd03316660af8ba747fae6de91249cc807e043dba4cae11295b0f43446684421bf2731fd6fab
|
data/Gemfile.lock
CHANGED
@@ -20,6 +20,10 @@
|
|
20
20
|
|
21
21
|
*** open
|
22
22
|
- 使用方法...変数 = File.open(file_path, mode, perm, opt)
|
23
|
+
もしくは
|
24
|
+
File.open(ファイル名,"w") do |text|
|
25
|
+
ファイルに対する処理
|
26
|
+
end
|
23
27
|
- 機能...ファイルの内容を変数に格納します.modeとpermとoptは省略可能です.
|
24
28
|
しかしmodeとpermに関してはmodeを省略するとpermは使用できません.
|
25
29
|
- mode...どのような目的でファイルを開くかを決定します.ex) "r" は読み込み専用, "w"は書き込み専用....
|
@@ -32,7 +36,21 @@
|
|
32
36
|
- 機能...オブジェクトのファイルを閉じます.
|
33
37
|
- File.openした変数が閉じているかどうかを確認する場合は,File.closed?でtrue/falseの結果を得ることができます.
|
34
38
|
|
35
|
-
***
|
39
|
+
*** each_line
|
40
|
+
- 使用方法...file = File.open(ファイル名)
|
41
|
+
file.each_line(引数) do |変数|
|
42
|
+
ファイルの各行に対して繰り返したい処理
|
43
|
+
end
|
44
|
+
file.close
|
45
|
+
- 機能...ファイルの各行をそれぞれ処理するメソッド。
|
46
|
+
ファイルを1行ずつ読み込み、処理を繰り返す。
|
47
|
+
行の区切りは引数で指定した文字列になる.
|
48
|
+
引数が省略された場合は,\nで行が区切られる.
|
49
|
+
*** puts
|
50
|
+
- 使用方法...File.open(ファイル名,"w") do |text|
|
51
|
+
text.puts(書き加える文字)
|
52
|
+
end
|
53
|
+
- 機能...文字を書き加える.ただし,文字は上書きされる.
|
36
54
|
** read
|
37
55
|
- 使用方法...変数 = File.read(file_path)
|
38
56
|
- 機能...File.openなしにファイルに書かれている内容を変数に格納する.
|
@@ -41,3 +59,4 @@
|
|
41
59
|
- 使用方法...File.write(file_path, data, offset)
|
42
60
|
- 機能...File.openなしにファイルをdataに書き換える.
|
43
61
|
offsetは省略可能だが,指定した場合は書き換えるのではなく,指定したoffset番目の文字がdataに書き換わる.
|
62
|
+
|
@@ -1 +1 @@
|
|
1
|
-
#
|
1
|
+
# section_10/part_1/workplace.rb
|
@@ -1,7 +1,11 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
filename =
|
1
|
+
# section_10/part_2/answer.rb
|
2
|
+
# 10-2-file-open.rb
|
3
|
+
filename = STDIN.gets.chomp
|
4
|
+
file_texts = []
|
4
5
|
file = File.open(filename)
|
5
6
|
file.each_line do |line|
|
6
|
-
|
7
|
+
file_texts << line
|
7
8
|
end
|
9
|
+
file.close
|
10
|
+
puts file_texts[0]
|
11
|
+
puts file_texts[2]
|
@@ -1,15 +1,64 @@
|
|
1
|
-
|
1
|
+
-課題-
|
2
|
+
キーボードから1つの文字列を受け取り、文字列と一致するファイル名のテキストデータから、0行目と2行目をputsで表示するプログラムを作成せよ。
|
2
3
|
|
4
|
+
* ファイル操作
|
5
|
+
- ファイル操作にはファイル入出力等のコードからファイルに関する操作ができるメソッドを紹介します.
|
6
|
+
- 例によって,この項目についても様々な機能があるので必要最低限の知識を掲載することにします.
|
7
|
+
- 以下の解説に出てくるfile_pathは全てファイルのアドレスを意味します.
|
8
|
+
** fileのpath
|
9
|
+
- ファイルが存在するアドレスをパス(path)という.
|
3
10
|
|
4
|
-
|
11
|
+
** open and close
|
12
|
+
- ファイルの操作を行う場合の基本.
|
13
|
+
- openはファイルを開いて新しいFileオブジェクトを得る.
|
14
|
+
- closeはopenで得たFileオブジェクトを閉じる.
|
15
|
+
- 1つのプログラムが同時に開くことのできるファイル数には制限があるので,使い終わったファイルはなるべく閉じるようにすべきです.なので必ずopenした数だけcloseを行いましょう.
|
16
|
+
- File.openにはFile.closeを必要としない記法もあります.eachメソッドに酷似しているので以下に示します.
|
17
|
+
ex) File.open(file_path) do |変数|
|
18
|
+
変数にはopenしたファイルが入っているので,それに対しての処理.
|
19
|
+
end
|
20
|
+
|
21
|
+
*** open
|
22
|
+
- 使用方法...変数 = File.open(file_path, mode, perm, opt)
|
23
|
+
もしくは
|
24
|
+
File.open(ファイル名,"w") do |text|
|
25
|
+
ファイルに対する処理
|
26
|
+
end
|
27
|
+
- 機能...ファイルの内容を変数に格納します.modeとpermとoptは省略可能です.
|
28
|
+
しかしmodeとpermに関してはmodeを省略するとpermは使用できません.
|
29
|
+
- mode...どのような目的でファイルを開くかを決定します.ex) "r" は読み込み専用, "w"は書き込み専用....
|
30
|
+
- perm...ここでは深く解説しませんが,ファイルはプログラム外ではコンピュータの中に保存されています.
|
31
|
+
しかし,そのファイルにはコンピュータ内でも読み込み専用等のmodeが付随しているので,permはそのmodeの変更を行えます.
|
32
|
+
- opt...その他のオプションです.かなり上級者向けの内容なのでここでは割愛します.
|
33
|
+
|
34
|
+
*** close
|
35
|
+
- 使用方法...(File.openで作成されたオブジェクトを持つ変数より後に)File.close
|
36
|
+
- 機能...オブジェクトのファイルを閉じます.
|
37
|
+
- File.openした変数が閉じているかどうかを確認する場合は,File.closed?でtrue/falseの結果を得ることができます.
|
38
|
+
|
39
|
+
*** each_line
|
40
|
+
- 使用方法...file = File.open(ファイル名)
|
41
|
+
file.each_line(引数) do |変数|
|
42
|
+
ファイルの各行に対して繰り返したい処理
|
43
|
+
end
|
44
|
+
file.close
|
45
|
+
- 機能...ファイルの各行をそれぞれ処理するメソッド。
|
46
|
+
ファイルを1行ずつ読み込み、処理を繰り返す。
|
47
|
+
行の区切りは引数で指定した文字列になる.
|
48
|
+
引数が省略された場合は,\nで行が区切られる.
|
49
|
+
*** puts
|
50
|
+
- 使用方法...File.open(ファイル名,"w") do |text|
|
51
|
+
text.puts(書き加える文字)
|
52
|
+
end
|
53
|
+
- 機能...文字を書き加える.ただし,文字は上書きされる.
|
54
|
+
** read
|
55
|
+
- 使用方法...変数 = File.read(file_path, length)
|
56
|
+
- 機能...File.openなしにファイルに書かれている内容を変数に格納する.lengthは先頭から何文字目まで読み込むかを決め,省略可能である.
|
57
|
+
|
58
|
+
** write
|
59
|
+
- 使用方法...File.write(file_path, data, offset)
|
60
|
+
- 機能...File.openなしにファイルをdataに書き換える.
|
61
|
+
offsetは省略可能だが,指定した場合は書き換えるのではなく,指定したoffset番目の文字がdataに書き換わる.
|
5
62
|
|
6
|
-
file = File.open(ファイル名)
|
7
|
-
file.each_line do |変数|
|
8
|
-
繰り返したい処理
|
9
|
-
end
|
10
|
-
file.close
|
11
63
|
|
12
|
-
each_lineメソッドはファイルの各行をそれぞれ処理するメソッド。
|
13
|
-
ファイルを1行ずつ読み込み、処理を繰り返す。
|
14
64
|
|
15
|
-
open,closeメソッドはそれぞれファイルを読み込むためにファイルを開くメソッド、開いたファイルを閉じるメソッド。
|
@@ -1 +1 @@
|
|
1
|
-
#
|
1
|
+
# section_10/part_2/workplace.rb
|
@@ -4,7 +4,7 @@ require "open3"
|
|
4
4
|
RSpec.describe "ARGV-check" do
|
5
5
|
it 'given "for-read.txt", return 4' do
|
6
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
|
7
|
+
stdout, stderr, status = Open3.capture3("ruby #{workshop}/lib/workplace.rb", :stdin_data=>"#{workshop}/lib/for-read.txt")
|
8
|
+
expect { puts stdout }.to output("このファイルはファイル読み込み用の練習ファイルです。\nむかしむかし、あるところに、おじいさんとおばあさんが住んでいました。\n").to_stdout
|
9
9
|
end
|
10
10
|
end
|
@@ -1,12 +1,9 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
|
4
|
-
filename = ARGV[1]
|
1
|
+
# section_10/part_3/answer.rb
|
2
|
+
# 10-3-file-write.rb
|
3
|
+
filename = STDIN.gets.chomp
|
5
4
|
|
6
|
-
file = File.open(filename)
|
7
|
-
file.
|
8
|
-
if pattern =~ line
|
9
|
-
print line
|
10
|
-
end
|
11
|
-
end
|
5
|
+
file = File.open(filename, 'w+')
|
6
|
+
file.puts('Hello, Ruby.')
|
12
7
|
file.close
|
8
|
+
|
9
|
+
puts File.read(filename)
|
@@ -1,8 +1,61 @@
|
|
1
|
-
|
1
|
+
-課題-
|
2
|
+
キーボードから1つの文字列を受け取り、その文字列に一致するファイルを開き,「Hello, Ruby.」を書き加えよ.その後,書き加えたファイルを表示せよ.
|
2
3
|
|
4
|
+
* ファイル操作
|
5
|
+
- ファイル操作にはファイル入出力等のコードからファイルに関する操作ができるメソッドを紹介します.
|
6
|
+
- 例によって,この項目についても様々な機能があるので必要最低限の知識を掲載することにします.
|
7
|
+
- 以下の解説に出てくるfile_pathは全てファイルのアドレスを意味します.
|
8
|
+
** fileのpath
|
9
|
+
- ファイルが存在するアドレスをパス(path)という.
|
3
10
|
|
4
|
-
|
11
|
+
** open and close
|
12
|
+
- ファイルの操作を行う場合の基本.
|
13
|
+
- openはファイルを開いて新しいFileオブジェクトを得る.
|
14
|
+
- closeはopenで得たFileオブジェクトを閉じる.
|
15
|
+
- 1つのプログラムが同時に開くことのできるファイル数には制限があるので,使い終わったファイルはなるべく閉じるようにすべきです.なので必ずopenした数だけcloseを行いましょう.
|
16
|
+
- File.openにはFile.closeを必要としない記法もあります.eachメソッドに酷似しているので以下に示します.
|
17
|
+
ex) File.open(file_path) do |変数|
|
18
|
+
変数にはopenしたファイルが入っているので,それに対しての処理.
|
19
|
+
end
|
5
20
|
|
6
|
-
|
21
|
+
*** open
|
22
|
+
- 使用方法...変数 = File.open(file_path, mode, perm, opt)
|
23
|
+
もしくは
|
24
|
+
File.open(ファイル名,"w") do |text|
|
25
|
+
ファイルに対する処理
|
26
|
+
end
|
27
|
+
- 機能...ファイルの内容を変数に格納します.modeとpermとoptは省略可能です.
|
28
|
+
しかしmodeとpermに関してはmodeを省略するとpermは使用できません.
|
29
|
+
- mode...どのような目的でファイルを開くかを決定します.ex) "r" は読み込み専用, "w"は書き込み専用....
|
30
|
+
- perm...ここでは深く解説しませんが,ファイルはプログラム外ではコンピュータの中に保存されています.
|
31
|
+
しかし,そのファイルにはコンピュータ内でも読み込み専用等のmodeが付随しているので,permはそのmodeの変更を行えます.
|
32
|
+
- opt...その他のオプションです.かなり上級者向けの内容なのでここでは割愛します.
|
7
33
|
|
8
|
-
|
34
|
+
*** close
|
35
|
+
- 使用方法...(File.openで作成されたオブジェクトを持つ変数より後に)File.close
|
36
|
+
- 機能...オブジェクトのファイルを閉じます.
|
37
|
+
- File.openした変数が閉じているかどうかを確認する場合は,File.closed?でtrue/falseの結果を得ることができます.
|
38
|
+
|
39
|
+
*** each_line
|
40
|
+
- 使用方法...file = File.open(ファイル名)
|
41
|
+
file.each_line(引数) do |変数|
|
42
|
+
ファイルの各行に対して繰り返したい処理
|
43
|
+
end
|
44
|
+
file.close
|
45
|
+
- 機能...ファイルの各行をそれぞれ処理するメソッド。
|
46
|
+
ファイルを1行ずつ読み込み、処理を繰り返す。
|
47
|
+
行の区切りは引数で指定した文字列になる.
|
48
|
+
引数が省略された場合は,\nで行が区切られる.
|
49
|
+
*** puts
|
50
|
+
- 使用方法...File.open(ファイル名,"w") do |text|
|
51
|
+
text.puts(書き加える文字)
|
52
|
+
end
|
53
|
+
- 機能...文字を書き加える.ただし,文字は上書きされる.
|
54
|
+
** read
|
55
|
+
- 使用方法...変数 = File.read(file_path, length)
|
56
|
+
- 機能...File.openなしにファイルに書かれている内容を変数に格納する.lengthは先頭から何文字目まで読み込むかを決め,省略可能である.
|
57
|
+
|
58
|
+
** write
|
59
|
+
- 使用方法...File.write(file_path, data, offset)
|
60
|
+
- 機能...File.openなしにファイルをdataに書き換える.
|
61
|
+
offsetは省略可能だが,指定した場合は書き換えるのではなく,指定したoffset番目の文字がdataに書き換わる.
|
@@ -1 +1 @@
|
|
1
|
-
#
|
1
|
+
# section_10/part_3/workplace.rb
|
@@ -4,7 +4,7 @@ require "open3"
|
|
4
4
|
RSpec.describe "ARGV-check" do
|
5
5
|
it 'given 3 "for-read.txt", return 4' do
|
6
6
|
workshop = "#{ENV['HOME']}/.ruby_learner/workshop"
|
7
|
-
stdout, stderr, status = Open3.capture3("ruby #{workshop}/lib/workplace.rb
|
8
|
-
expect { puts stdout }.to output("
|
7
|
+
stdout, stderr, status = Open3.capture3("ruby #{workshop}/lib/workplace.rb", :stdin_data=>"#{workshop}/lib/mk-read.txt")
|
8
|
+
expect { puts stdout }.to output("Hello, Ruby.\n").to_stdout
|
9
9
|
end
|
10
10
|
end
|
@@ -1,13 +1,26 @@
|
|
1
|
-
|
1
|
+
-課題-
|
2
|
+
1つの文字列を引数にして,「Hello, (受け取った文字列).」と表示するメソッドhelloが書かれたプログラムfor-def-read.rbがある.
|
3
|
+
このプログラムを取り込んでコマンドラインから1つの文字列を受け取り,その文字列を引数にしてfor-def-read.rbのメソッドhelloを実行するプログラムを作成せよ。
|
2
4
|
|
3
|
-
このプログラムを取り込んで、1つの文字列を受け取り、「Hello, 受け取った文字列.」と表示するプログラムを作成せよ。
|
4
5
|
|
6
|
+
* ライブラリの読み込み
|
7
|
+
- 他のファイルに記載されている関数等のプログラムを使用したい場合は,ライブラリの読み込みを行う.
|
5
8
|
|
6
|
-
|
9
|
+
** require_relative
|
10
|
+
- 使用方法...require_relative 使いたいファイルの相対パス
|
7
11
|
|
8
|
-
|
12
|
+
- 機能...他のファイル(ライブラリ)を読み込むためのメソッド.
|
13
|
+
Rubyは引数に指定されたライブラリを探して,そのファイルに書かれた内容を読み込む.
|
14
|
+
読み込みが終わると再び,メソッドの次の行から処理を再開する.
|
15
|
+
ファイルのパスは相対パスで記載する.
|
16
|
+
|
17
|
+
** require
|
18
|
+
- 使用方法...require 使いたいファイルの絶対パス(もしくは標準ライブラリ名)
|
9
19
|
|
10
|
-
require_relative
|
11
|
-
|
20
|
+
- 機能...基本的にrequire_relativeと同様の機能を持つ.
|
21
|
+
ファイルのパスは絶対パスで記載する.
|
22
|
+
Rubyにはいくつかの標準ライブラリと呼ばれるライブラリが用意されている.それらを使う場合はこちらを用いる.
|
12
23
|
|
13
|
-
|
24
|
+
* 相対パスと絶対パス
|
25
|
+
- 相対パス...実行中のファイルからみた他のファイルのパス.
|
26
|
+
- 絶対パス...コンピュータ内のファイルの位置.
|
@@ -2,14 +2,26 @@
|
|
2
2
|
require "open3"
|
3
3
|
|
4
4
|
RSpec.describe "ARGV-check" do
|
5
|
+
is_requireRe_method = false
|
6
|
+
workshop = "#{ENV['HOME']}/.ruby_learner/workshop"
|
7
|
+
filename = "#{workshop}/lib/workplace.rb"
|
8
|
+
it 'check requireRe-method, return boolean' do
|
9
|
+
File.open(filename, "r") do |file|
|
10
|
+
file.each_line do |line|
|
11
|
+
is_requireRe_method = true if line.include?("require_relative")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
puts "ErrorMessage: you don't use requireRe-method." if !is_requireRe_method
|
15
|
+
|
16
|
+
expect( is_requireRe_method ).to eq(true)
|
17
|
+
end
|
18
|
+
|
5
19
|
it 'given "tanaka", return "Hello, tanaka.\n"' do
|
6
|
-
|
7
|
-
stdout, stderr, status = Open3.capture3("ruby #{workshop}/lib/workplace.rb 'tanaka'")
|
20
|
+
stdout, stderr, status = Open3.capture3("ruby #{filename} 'tanaka'")
|
8
21
|
expect { puts stdout }.to output("Hello, tanaka.\n").to_stdout
|
9
22
|
end
|
10
23
|
it 'given "yamada", return "Hello, yamada.\n"' do
|
11
|
-
|
12
|
-
stdout, stderr, status = Open3.capture3("ruby #{workshop}/lib/workplace.rb 'yamada'")
|
24
|
+
stdout, stderr, status = Open3.capture3("ruby #{filename} 'yamada'")
|
13
25
|
expect { puts stdout }.to output("Hello, yamada.\n").to_stdout
|
14
26
|
end
|
15
27
|
end
|
@@ -1,9 +1,28 @@
|
|
1
|
+
-課題-
|
1
2
|
Rubyの標準ライブラリ「date」を用いて、Rubyが誕生した1993年2月24日から、今日までの日数を表示するプログラムを作成せよ。
|
3
|
+
詳しい「date」ライブラリの使い方に関してはインターネットで検索して調べよ.
|
2
4
|
|
5
|
+
検索ヒント: ruby,date,ライブラリ
|
3
6
|
|
4
|
-
- requireメソッド
|
5
7
|
|
6
|
-
|
8
|
+
* ライブラリの読み込み
|
9
|
+
- 他のファイルに記載されている関数等のプログラムを使用したい場合は,ライブラリの読み込みを行う.
|
7
10
|
|
8
|
-
|
9
|
-
|
11
|
+
** require_relative
|
12
|
+
- 使用方法...require_relative 使いたいファイルの相対パス
|
13
|
+
|
14
|
+
- 機能...他のファイル(ライブラリ)を読み込むためのメソッド.
|
15
|
+
Rubyは引数に指定されたライブラリを探して,そのファイルに書かれた内容を読み込む.
|
16
|
+
読み込みが終わると再び,メソッドの次の行から処理を再開する.
|
17
|
+
ファイルのパスは相対パスで記載する.
|
18
|
+
|
19
|
+
** require
|
20
|
+
- 使用方法...require 使いたいファイルの絶対パス(もしくは標準ライブラリ名)
|
21
|
+
|
22
|
+
- 機能...基本的にrequire_relativeと同様の機能を持つ.
|
23
|
+
ファイルのパスは絶対パスで記載する.
|
24
|
+
Rubyにはいくつかの標準ライブラリと呼ばれるライブラリが用意されている.それらを使う場合はこちらを用いる.
|
25
|
+
|
26
|
+
* 相対パスと絶対パス
|
27
|
+
- 相対パス...実行中のファイルからみた他のファイルのパス.
|
28
|
+
- 絶対パス...コンピュータ内のファイルの位置.
|
@@ -0,0 +1,26 @@
|
|
1
|
+
-課題-
|
2
|
+
1つの文字列を引数にして,「Hello, (受け取った文字列).」と表示するメソッドhelloが書かれたプログラムfor-def-read.rbがある.
|
3
|
+
このプログラムを取り込んでコマンドラインから1つの文字列を受け取り,その文字列を引数にしてfor-def-read.rbのメソッドhelloを実行するプログラムを作成せよ。
|
4
|
+
requireを用いること.絶対パスは'#{ENV['HOME']}/.ruby_learner/workshop/lib/for-def-read.rb'である.
|
5
|
+
|
6
|
+
* ライブラリの読み込み
|
7
|
+
- 他のファイルに記載されている関数等のプログラムを使用したい場合は,ライブラリの読み込みを行う.
|
8
|
+
|
9
|
+
** require_relative
|
10
|
+
- 使用方法...require_relative 使いたいファイルの相対パス
|
11
|
+
|
12
|
+
- 機能...他のファイル(ライブラリ)を読み込むためのメソッド.
|
13
|
+
Rubyは引数に指定されたライブラリを探して,そのファイルに書かれた内容を読み込む.
|
14
|
+
読み込みが終わると再び,メソッドの次の行から処理を再開する.
|
15
|
+
ファイルのパスは相対パスで記載する.
|
16
|
+
|
17
|
+
** require
|
18
|
+
- 使用方法...require 使いたいファイルの絶対パス(もしくは標準ライブラリ名)
|
19
|
+
|
20
|
+
- 機能...基本的にrequire_relativeと同様の機能を持つ.
|
21
|
+
ファイルのパスは絶対パスで記載する.
|
22
|
+
Rubyにはいくつかの標準ライブラリと呼ばれるライブラリが用意されている.それらを使う場合はこちらを用いる.
|
23
|
+
|
24
|
+
* 相対パスと絶対パス
|
25
|
+
- 相対パス...実行中のファイルからみた他のファイルのパス.
|
26
|
+
- 絶対パス...コンピュータ内のファイルの位置.
|
@@ -0,0 +1 @@
|
|
1
|
+
# section_11/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,28 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require "open3"
|
3
|
+
|
4
|
+
RSpec.describe "ARGV-check" do
|
5
|
+
|
6
|
+
is_require_method = false
|
7
|
+
workshop = "#{ENV['HOME']}/.ruby_learner/workshop"
|
8
|
+
filename = "#{workshop}/lib/workplace.rb"
|
9
|
+
it 'check require-method, return boolean' do
|
10
|
+
File.open(filename, "r") do |file|
|
11
|
+
file.each_line do |line|
|
12
|
+
is_require_method = true if line.include?("require\"") || line.include?("require ") || line.include?("require'")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
puts "ErrorMessage: you don't use require-method." if !is_require_method
|
16
|
+
|
17
|
+
expect( is_require_method ).to eq(true)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'given "tanaka", return "Hello, tanaka.\n"' do
|
21
|
+
stdout, stderr, status = Open3.capture3("ruby #{filename} 'tanaka'")
|
22
|
+
expect { puts stdout }.to output("Hello, tanaka.\n").to_stdout
|
23
|
+
end
|
24
|
+
it 'given "yamada", return "Hello, yamada.\n"' do
|
25
|
+
stdout, stderr, status = Open3.capture3("ruby #{filename} 'yamada'")
|
26
|
+
expect { puts stdout }.to output("Hello, yamada.\n").to_stdout
|
27
|
+
end
|
28
|
+
end
|
@@ -60,8 +60,8 @@ class SequentialMain
|
|
60
60
|
puts "section_7\t 1~3\t function"
|
61
61
|
puts "section_8\t 1~3\t class"
|
62
62
|
puts "section_9\t 1~3\t regular_expression"
|
63
|
-
puts "section_10\t 1~
|
64
|
-
puts "section_11\t 1~
|
63
|
+
puts "section_10\t 1~3\t file_operation"
|
64
|
+
puts "section_11\t 1~3\t library"
|
65
65
|
end
|
66
66
|
|
67
67
|
def get_final_history()
|
data/lib/ruby_learner/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_learner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takaki Otsu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -180,6 +180,11 @@ files:
|
|
180
180
|
- contents/questions/sequential_check/section_11/part_2/lib/workplace.rb
|
181
181
|
- contents/questions/sequential_check/section_11/part_2/spec/spec_helper.rb
|
182
182
|
- contents/questions/sequential_check/section_11/part_2/spec/workplace_spec.rb
|
183
|
+
- contents/questions/sequential_check/section_11/part_3/lib/answer.rb
|
184
|
+
- contents/questions/sequential_check/section_11/part_3/lib/sentence.org
|
185
|
+
- contents/questions/sequential_check/section_11/part_3/lib/workplace.rb
|
186
|
+
- contents/questions/sequential_check/section_11/part_3/spec/spec_helper.rb
|
187
|
+
- contents/questions/sequential_check/section_11/part_3/spec/workplace_spec.rb
|
183
188
|
- |
|
184
189
|
contents/questions/sequential_check/section_2/foo
|
185
190
|
bar
|