ruby_learner 1.1.14 → 1.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/ruby_learner/sequential_main.rb +19 -5
- data/lib/ruby_learner/version.rb +1 -1
- data/questions/sequential_check/section_1/part_1/lib/sentence.org +17 -6
- data/questions/sequential_check/section_1/part_1/spec/workplace_spec.rb +1 -1
- data/questions/sequential_check/section_1/part_2/lib/sentence.org +16 -6
- data/questions/sequential_check/section_1/part_3/lib/sentence.org +17 -7
- data/questions/sequential_check/section_2/part_1/lib/sentence.org +17 -6
- data/questions/sequential_check/section_2/part_2/lib/sentence.org +43 -0
- data/questions/sequential_check/section_2/part_3/lib/sentence.org +22 -5
- data/questions/sequential_check/section_2/part_3/spec/workplace_spec.rb +2 -2
- data/questions/sequential_check/section_3/part_1/lib/sentence.org +56 -0
- data/questions/sequential_check/section_3/part_3/lib/answer.rb +5 -0
- data/questions/sequential_check/section_3/part_3/lib/sentence.org +6 -0
- data/questions/sequential_check/section_3/part_3/lib/workplace.rb +2 -0
- data/questions/sequential_check/section_3/part_3/spec/spec_helper.rb +100 -0
- data/questions/sequential_check/section_3/part_3/spec/workplace_spec.rb +9 -0
- data/questions/sequential_check/section_4/part_1/lib/answer.rb +19 -8
- data/questions/sequential_check/section_4/part_1/lib/sentence.org +94 -11
- data/questions/sequential_check/section_4/part_1/lib/workplace.rb +17 -0
- data/questions/sequential_check/section_4/part_1/spec/workplace_spec.rb +5 -10
- data/questions/sequential_check/section_4/part_2/lib/answer.rb +9 -0
- data/questions/sequential_check/section_4/part_2/lib/sentence.org +85 -0
- data/questions/sequential_check/section_4/part_2/lib/workplace.rb +2 -0
- data/questions/sequential_check/section_4/part_2/spec/spec_helper.rb +100 -0
- data/questions/sequential_check/section_4/part_2/spec/workplace_spec.rb +14 -0
- data/questions/sequential_check/section_4/part_3/lib/answer.rb +13 -0
- data/questions/sequential_check/section_4/part_3/lib/sentence.org +88 -0
- data/questions/sequential_check/section_4/part_3/lib/workplace.rb +4 -0
- data/questions/sequential_check/section_4/part_3/spec/spec_helper.rb +100 -0
- data/questions/sequential_check/section_4/part_3/spec/workplace_spec.rb +29 -0
- data/questions/sequential_check/section_5/part_1/lib/answer.rb +3 -3
- data/questions/sequential_check/section_5/part_1/lib/sentence.org +60 -7
- data/questions/sequential_check/section_5/part_1/lib/workplace.rb +1 -0
- data/questions/sequential_check/section_5/part_1/spec/workplace_spec.rb +30 -9
- data/questions/sequential_check/section_5/part_2/lib/answer.rb +11 -2
- data/questions/sequential_check/section_5/part_2/lib/sentence.org +70 -6
- data/questions/sequential_check/section_5/part_2/lib/workplace.rb +9 -0
- data/questions/sequential_check/section_5/part_2/spec/workplace_spec.rb +18 -5
- data/questions/sequential_check/section_5/part_3/lib/answer.rb +17 -0
- data/questions/sequential_check/section_5/part_3/lib/sentence.org +74 -0
- data/questions/sequential_check/section_5/part_3/lib/workplace.rb +10 -0
- data/questions/sequential_check/section_5/part_3/spec/spec_helper.rb +100 -0
- data/questions/sequential_check/section_5/part_3/spec/workplace_spec.rb +22 -0
- data/questions/sequential_check/section_6/part_1/lib/answer.rb +7 -2
- data/questions/sequential_check/section_6/part_1/lib/sentence.org +13 -14
- data/questions/sequential_check/section_6/part_1/lib/workplace.rb +2 -0
- data/questions/sequential_check/section_6/part_1/spec/workplace_spec.rb +21 -9
- data/questions/sequential_check/section_6/part_2/lib/sentence.org +1 -0
- data/workshop/rubocop.yml +2 -0
- metadata +22 -2
|
@@ -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,9 @@
|
|
|
1
|
+
require "open3"
|
|
2
|
+
|
|
3
|
+
RSpec.describe "array-check" do
|
|
4
|
+
it 'return "表面積=76\n体積=40\n"' do
|
|
5
|
+
workshop = "#{ENV['HOME']}/.ruby_learner/workshop"
|
|
6
|
+
stdout, stderr, status = Open3.capture3("ruby #{workshop}/lib/workplace.rb")
|
|
7
|
+
expect { puts stdout }.to output("[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n").to_stdout
|
|
8
|
+
end
|
|
9
|
+
end
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
# section_4/part_1/answer.rb
|
|
2
|
-
# 4-1-
|
|
3
|
-
a =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
# 4-1-trueAndFalse.rb
|
|
3
|
+
a = 50
|
|
4
|
+
b = 50
|
|
5
|
+
|
|
6
|
+
# output following results
|
|
7
|
+
p a == b # a == b
|
|
8
|
+
p a != b # a != b
|
|
9
|
+
|
|
10
|
+
a = 50
|
|
11
|
+
b = 150
|
|
12
|
+
|
|
13
|
+
p a > b # a > b
|
|
14
|
+
p a < b # a < b
|
|
15
|
+
|
|
16
|
+
c = 10
|
|
17
|
+
d = 10
|
|
18
|
+
|
|
19
|
+
p a < b && c == d # a < b && c == d
|
|
20
|
+
p a < b || c == d # a < b || c == d
|
|
@@ -1,16 +1,99 @@
|
|
|
1
|
-
|
|
1
|
+
-課題-
|
|
2
|
+
与えられた変数aとbを用いて,記述されているコメントの演算子の結果をpを用いて標準出力に出力せよ.
|
|
2
3
|
|
|
4
|
+
* コメント文
|
|
5
|
+
- コメント文の文字はプログラム実行には関係のないメッセージとなる.
|
|
6
|
+
** シャープ(#)コメント
|
|
7
|
+
- シャープ(#)からその行の終わりまでに書かれた文字がコメントとなる.
|
|
3
8
|
|
|
4
|
-
|
|
9
|
+
** begin・endコメント
|
|
10
|
+
- =begin
|
|
11
|
+
コメント記述
|
|
12
|
+
=end
|
|
13
|
+
- 上記の通り,=beginと=endで挟まれた数行は全てコメントとなる.
|
|
5
14
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
else
|
|
9
|
-
条件が成り立たなかったときに実行したい処理
|
|
10
|
-
end
|
|
15
|
+
** ENDコメント
|
|
16
|
+
- __END__と記入すると,それ以下の行が全てコメントとなる.
|
|
11
17
|
|
|
18
|
+
* 擬似変数
|
|
19
|
+
- 数ある変数の内の1つ.
|
|
20
|
+
- 疑似変数の値を変更することはできない.
|
|
21
|
+
- 今回はtrue,false,nilを紹介する.
|
|
22
|
+
- true, false...比較演算の結果や条件を表すメソッドの結果として多く用いられる.これらを変数の結果として格納することも可能.
|
|
23
|
+
- nil...オブジェクトが存在していないことを表す.
|
|
24
|
+
|
|
25
|
+
* 真偽値
|
|
26
|
+
- 真...falseとnilを除くオブジェクト全て.
|
|
27
|
+
- 偽...falseとnil
|
|
28
|
+
|
|
29
|
+
* 条件分岐
|
|
30
|
+
- 条件によってプログラムの挙動を変える際に用いるメソッド.
|
|
31
|
+
- 条件には値が「true」か「false」となる式を書くのが一般的.
|
|
32
|
+
- 「nil」を返すオブジェクトも条件に使用できる.
|
|
33
|
+
|
|
34
|
+
** if
|
|
35
|
+
- 使用方法...if 条件 then 実行したい処理 end (if のメソッド内では「then」は省略可能.)
|
|
36
|
+
ex) if a>9 then
|
|
37
|
+
puts a
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
- 機能...条件が「true」の場合のみ,実行したい処理を行う.「else」と「elsif」を用いて,複雑な条件分岐を実行することができる.
|
|
41
|
+
ex) 使用方法の例を解説する.「『a』が9より大きい場合のみ,puts で『a』の値を表示する.」
|
|
42
|
+
|
|
43
|
+
*** elsifとelse
|
|
44
|
+
- 使用方法...if 条件1 then
|
|
45
|
+
条件1で実行したい処理
|
|
46
|
+
elsif 条件2 then
|
|
47
|
+
条件2で実行したい処理
|
|
48
|
+
else
|
|
49
|
+
条件1と条件2の両方に当てはまらない場合の処理
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
- 機能...条件を2つ以上使う場合は,条件2つ目から「if」ではなく「elsif」をつける.指定した条件の全てで「false」の場合の処理はelse内で記述する.
|
|
53
|
+
** unless
|
|
54
|
+
- if は条件が「true」の場合に処理を実行するメソッドであるが,unless は条件が「false」の場合に処理を実行するメソッドである.
|
|
55
|
+
- 使用方法...基本的にはif メソッドの「if」を「unless」に書き換えるだけである.しかし,unless メソッドにはif メソッドの「elsif」に該当する機能は無い.
|
|
56
|
+
ex) unless a>9 then
|
|
57
|
+
puts 'aは9以下'
|
|
58
|
+
else
|
|
59
|
+
puts 'aは9より大きい'
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
- 機能...条件が「false」の場合のみ,実行したい処理を行う.
|
|
63
|
+
ex) 使用方法の例を解説する.「『a』が『9より大きい』が『false』の場合は『aは9以下』,それ以外は『aは9より大きい』と表示する」
|
|
64
|
+
|
|
65
|
+
** case
|
|
66
|
+
- 使用方法...case 比較したいオブジェクト
|
|
67
|
+
when 値1 then
|
|
68
|
+
文1
|
|
69
|
+
when 値2 then
|
|
70
|
+
文2
|
|
71
|
+
else
|
|
72
|
+
文3
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
-機能...比較したいオブジェクトの値が値1の場合は文1が実行される.値2も同様である.elseはどの値にも当てはまらない場合に実行される.
|
|
76
|
+
|
|
77
|
+
* 結果が「true」や「false」となる式.(比較演算子)
|
|
78
|
+
- 条件を満たさない場合は「false」,それ以外は「true」を返す.
|
|
79
|
+
- ここでは関係演算子と論理演算子の2つを紹介する.
|
|
80
|
+
*** 関係演算子
|
|
81
|
+
- 左辺と右辺のオブジェクトが持つ数値や文字列を比較し,等しいか等しく無いか,また大きいか小さいかなどを比較することができる,
|
|
82
|
+
- 今回は2つのオブジェクト「a」と「b」の関係で解説していく.
|
|
83
|
+
|
|
84
|
+
- (具体例) a == b (意味)「b」が「a」に等しい.
|
|
85
|
+
- (具体例) a != b (意味)「b」が「a」に等くない.
|
|
86
|
+
- (具体例) a > b (意味)「a」は「b」より大きい.
|
|
87
|
+
- (具体例) a >= b (意味)「a」は「b」以上.
|
|
88
|
+
- (具体例) a < b (意味)「a」は「b」より小さい.
|
|
89
|
+
- (具体例) a <= b (意味)「a」は「b」以下.
|
|
90
|
+
|
|
91
|
+
- 「a」と「b」を関係演算子を用いて比較した結果として,関係演算子の持つ意味を満たす場合は「true」,満たさない場合は「false」を返す.
|
|
92
|
+
|
|
93
|
+
*** 論理演算子
|
|
94
|
+
- 複数の関係演算子を満たす場合の条件を書くときに,よく使われる条件の書き方.
|
|
95
|
+
- 今回は2つの条件式「A」と「B」の関係で解説していく.
|
|
96
|
+
- (具体例) A && B (意味)「A」と「B」が共に「true」の場合は「true」を返す.
|
|
97
|
+
- (具体例) A || B (意味)「A」と「B」のどちらか一方でも「true」の場合は「true」を返す.
|
|
98
|
+
- (具体例) !A (意味)「A」が「true」の場合は「false」,「false」の場合は「true」を返す.
|
|
12
99
|
|
|
13
|
-
条件によってプログラムの挙動を変える際に用いるメソッド。
|
|
14
|
-
条件には値がtrue かfalse となる式を書くのが一般的。
|
|
15
|
-
例えば、2つの値を比較して一致すればtrue,しなければfalseといった具合。
|
|
16
|
-
また、不等号は「<=」、等号は「==」を用いる。
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
require "open3"
|
|
2
2
|
|
|
3
|
-
RSpec.describe "
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
stdout, stderr, status = Open3.capture3("ruby #{workshop}/lib/workplace.rb
|
|
7
|
-
expect {
|
|
8
|
-
end
|
|
9
|
-
it 'given 10, return "greater\n"' do
|
|
10
|
-
workshop = "#{ENV['HOME']}/.ruby_learner/workshop"
|
|
11
|
-
stdout, stderr, status = Open3.capture3("ruby #{workshop}/lib/workplace.rb 10")
|
|
12
|
-
expect { puts stdout }.to output("greater\n").to_stdout
|
|
3
|
+
RSpec.describe "TrueAndFalse-check" do
|
|
4
|
+
workshop = "#{ENV['HOME']}/.ruby_learner/workshop"
|
|
5
|
+
it 'return "true\nfalse\nfalse\ntrue\ntrue\ntrue\n"' do
|
|
6
|
+
stdout, stderr, status = Open3.capture3("ruby #{workshop}/lib/workplace.rb")
|
|
7
|
+
expect { print "#{stdout}" }.to output("true\nfalse\nfalse\ntrue\ntrue\ntrue\n").to_stdout
|
|
13
8
|
end
|
|
14
9
|
end
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
-課題-
|
|
2
|
+
コマンドラインから1つの数字を受け取り,それが10より大きければ「greater」小さければ「smaller」を標準出力に表示するプログラムを作成せよ.出力結果の末尾は改行すること.
|
|
3
|
+
|
|
4
|
+
* 擬似変数
|
|
5
|
+
- 数ある変数の内の1つ.
|
|
6
|
+
- 疑似変数の値を変更することはできない.
|
|
7
|
+
- 今回はtrue,false,nilを紹介する.
|
|
8
|
+
- true, false...比較演算の結果や条件を表すメソッドの結果として多く用いられる.これらを変数の結果として格納することも可能.
|
|
9
|
+
- nil...オブジェクトが存在していないことを表す.
|
|
10
|
+
|
|
11
|
+
* 真偽値
|
|
12
|
+
- 真...falseとnilを除くオブジェクト全て.
|
|
13
|
+
- 偽...falseとnil
|
|
14
|
+
|
|
15
|
+
* 条件分岐
|
|
16
|
+
- 条件によってプログラムの挙動を変える際に用いるメソッド.
|
|
17
|
+
- 条件には値が「true」か「false」となる式を書くのが一般的.
|
|
18
|
+
- 「nil」を返すオブジェクトも条件に使用できる.
|
|
19
|
+
|
|
20
|
+
** if
|
|
21
|
+
- 使用方法...if 条件 then 実行したい処理 end (if のメソッド内では「then」は省略可能.)
|
|
22
|
+
ex) if a>9 then
|
|
23
|
+
puts a
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
- 機能...条件が「true」の場合のみ,実行したい処理を行う.「else」と「elsif」を用いて,複雑な条件分岐を実行することができる.
|
|
27
|
+
ex) 使用方法の例を解説する.「『a』が9より大きい場合のみ,puts で『a』の値を表示する.」
|
|
28
|
+
|
|
29
|
+
*** elsifとelse
|
|
30
|
+
- 使用方法...if 条件1 then
|
|
31
|
+
条件1で実行したい処理
|
|
32
|
+
elsif 条件2 then
|
|
33
|
+
条件2で実行したい処理
|
|
34
|
+
else
|
|
35
|
+
条件1と条件2の両方に当てはまらない場合の処理
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
- 機能...条件を2つ以上使う場合は,条件2つ目から「if」ではなく「elsif」をつける.指定した条件の全てで「false」の場合の処理はelse内で記述する.
|
|
39
|
+
** unless
|
|
40
|
+
- if は条件が「true」の場合に処理を実行するメソッドであるが,unless は条件が「false」の場合に処理を実行するメソッドである.
|
|
41
|
+
- 使用方法...基本的にはif メソッドの「if」を「unless」に書き換えるだけである.しかし,unless メソッドにはif メソッドの「elsif」に該当する機能は無い.
|
|
42
|
+
ex) unless a>9 then
|
|
43
|
+
puts 'aは9以下'
|
|
44
|
+
else
|
|
45
|
+
puts 'aは9より大きい'
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
- 機能...条件が「false」の場合のみ,実行したい処理を行う.
|
|
49
|
+
ex) 使用方法の例を解説する.「『a』が『9より大きい』が『false』の場合は『aは9以下』,それ以外は『aは9より大きい』と表示する」
|
|
50
|
+
|
|
51
|
+
** case
|
|
52
|
+
- 使用方法...case 比較したいオブジェクト
|
|
53
|
+
when 値1 then
|
|
54
|
+
文1
|
|
55
|
+
when 値2 then
|
|
56
|
+
文2
|
|
57
|
+
else
|
|
58
|
+
文3
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
-機能...比較したいオブジェクトの値が値1の場合は文1が実行される.値2も同様である.elseはどの値にも当てはまらない場合に実行される.
|
|
62
|
+
|
|
63
|
+
* 結果が「true」や「false」となる式.(比較演算子)
|
|
64
|
+
- 条件を満たさない場合は「false」,それ以外は「true」を返す.
|
|
65
|
+
- ここでは関係演算子と論理演算子の2つを紹介する.
|
|
66
|
+
*** 関係演算子
|
|
67
|
+
- 左辺と右辺のオブジェクトが持つ数値や文字列を比較し,等しいか等しく無いか,また大きいか小さいかなどを比較することができる,
|
|
68
|
+
- 今回は2つのオブジェクト「a」と「b」の関係で解説していく.
|
|
69
|
+
|
|
70
|
+
- (具体例) a == b (意味)「b」が「a」に等しい.
|
|
71
|
+
- (具体例) a != b (意味)「b」が「a」に等くない.
|
|
72
|
+
- (具体例) a > b (意味)「a」は「b」より大きい.
|
|
73
|
+
- (具体例) a >= b (意味)「a」は「b」以上.
|
|
74
|
+
- (具体例) a < b (意味)「a」は「b」より小さい.
|
|
75
|
+
- (具体例) a <= b (意味)「a」は「b」以下.
|
|
76
|
+
|
|
77
|
+
- 「a」と「b」を関係演算子を用いて比較した結果として,関係演算子の持つ意味を満たす場合は「true」,満たさない場合は「false」を返す.
|
|
78
|
+
|
|
79
|
+
*** 論理演算子
|
|
80
|
+
- 複数の関係演算子を満たす場合の条件を書くときに,よく使われる条件の書き方.
|
|
81
|
+
- 今回は2つの条件式「A」と「B」の関係で解説していく.
|
|
82
|
+
- (具体例) A && B (意味)「A」と「B」が共に「true」の場合は「true」を返す.
|
|
83
|
+
- (具体例) A || B (意味)「A」と「B」のどちらか一方でも「true」の場合は「true」を返す.
|
|
84
|
+
- (具体例) !A (意味)「A」が「true」の場合は「false」,「false」の場合は「true」を返す.
|
|
85
|
+
|
|
@@ -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
|