ruby_learner 1.2.0 → 1.2.1
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/answer.rb +5 -7
- data/contents/questions/sequential_check/section_10/part_1/lib/sentence.org +10 -8
- data/contents/questions/sequential_check/section_10/part_1/lib/workplace.rb +1 -1
- data/contents/questions/sequential_check/section_10/part_1/spec/workplace_spec.rb +4 -4
- data/contents/questions/sequential_check/section_10/part_2/lib/answer.rb +6 -7
- data/contents/questions/sequential_check/section_10/part_2/lib/sentence.org +9 -7
- 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 +4 -9
- data/contents/questions/sequential_check/section_10/part_3/lib/answer.rb +12 -0
- data/contents/questions/sequential_check/section_10/part_3/lib/sentence.org +8 -0
- data/contents/questions/sequential_check/section_10/part_3/lib/workplace.rb +1 -0
- data/contents/questions/sequential_check/{section_6/part_4 → section_10/part_3}/spec/spec_helper.rb +0 -0
- data/contents/questions/sequential_check/section_10/part_3/spec/workplace_spec.rb +10 -0
- data/contents/questions/sequential_check/section_2/foo/nbar/nbaz/n +0 -0
- data/contents/questions/sequential_check/section_2/part_3/lib/answer.rb +3 -6
- data/contents/questions/sequential_check/section_2/part_3/lib/sentence.org +2 -0
- data/contents/questions/sequential_check/section_2/part_3/lib/workplace.rb +0 -4
- data/contents/questions/sequential_check/section_2/part_3/spec/workplace_spec.rb +8 -7
- data/contents/questions/sequential_check/section_3/part_2/lib/answer.rb +3 -5
- data/contents/questions/sequential_check/section_3/part_2/lib/workplace.rb +0 -4
- data/contents/questions/sequential_check/section_3/part_2/spec/workplace_spec.rb +8 -7
- data/contents/questions/sequential_check/section_4/part_2/lib/answer.rb +2 -2
- data/contents/questions/sequential_check/section_4/part_2/lib/workplace.rb +1 -1
- data/contents/questions/sequential_check/section_4/part_3/lib/answer.rb +8 -10
- data/contents/questions/sequential_check/section_4/part_3/lib/sentence.org +1 -0
- data/contents/questions/sequential_check/section_4/part_3/lib/workplace.rb +1 -3
- data/contents/questions/sequential_check/section_4/part_3/spec/workplace_spec.rb +6 -7
- data/contents/questions/sequential_check/section_6/part_2/lib/answer.rb +9 -4
- data/contents/questions/sequential_check/section_6/part_2/lib/sentence.org +35 -2
- data/contents/questions/sequential_check/section_6/part_2/lib/workplace.rb +2 -0
- data/contents/questions/sequential_check/section_6/part_2/spec/workplace_spec.rb +9 -10
- data/contents/questions/sequential_check/section_6/part_3/lib/answer.rb +5 -5
- data/contents/questions/sequential_check/section_6/part_3/lib/sentence.org +44 -5
- data/contents/questions/sequential_check/section_6/part_3/lib/workplace.rb +3 -0
- data/contents/questions/sequential_check/section_6/part_3/spec/workplace_spec.rb +2 -2
- data/contents/questions/sequential_check/section_7/part_1/lib/answer.rb +5 -3
- data/contents/questions/sequential_check/section_7/part_1/lib/sentence.org +22 -16
- data/contents/questions/sequential_check/section_7/part_1/spec/workplace_spec.rb +8 -8
- data/contents/questions/sequential_check/section_7/part_2/lib/answer.rb +6 -6
- data/contents/questions/sequential_check/section_7/part_2/lib/sentence.org +23 -22
- data/contents/questions/sequential_check/section_7/part_2/spec/workplace_spec.rb +11 -5
- data/contents/questions/sequential_check/section_7/part_3/lib/answer.rb +13 -0
- data/contents/questions/sequential_check/section_7/part_3/lib/sentence.org +24 -0
- data/contents/questions/sequential_check/section_7/part_3/lib/workplace.rb +4 -0
- data/contents/questions/sequential_check/section_7/part_3/spec/spec_helper.rb +100 -0
- data/contents/questions/sequential_check/section_7/part_3/spec/workplace_spec.rb +15 -0
- data/contents/questions/sequential_check/section_8/part_1/lib/answer.rb +11 -6
- data/contents/questions/sequential_check/section_8/part_1/lib/sentence.org +66 -10
- data/contents/questions/sequential_check/section_8/part_1/lib/workplace.rb +10 -0
- data/contents/questions/sequential_check/section_8/part_1/spec/workplace_spec.rb +28 -9
- data/contents/questions/sequential_check/section_8/part_2/lib/answer.rb +14 -0
- data/contents/questions/sequential_check/section_8/part_2/lib/sentence.org +80 -0
- data/contents/questions/sequential_check/section_8/part_2/lib/workplace.rb +1 -0
- data/contents/questions/sequential_check/section_8/part_2/spec/spec_helper.rb +100 -0
- data/contents/questions/sequential_check/section_8/part_2/spec/workplace_spec.rb +34 -0
- data/contents/questions/sequential_check/section_8/part_3/lib/answer.rb +20 -0
- data/contents/questions/sequential_check/section_8/part_3/lib/sentence.org +80 -0
- data/contents/questions/sequential_check/section_8/part_3/lib/workplace.rb +11 -0
- data/contents/questions/sequential_check/section_8/part_3/spec/spec_helper.rb +100 -0
- data/contents/questions/sequential_check/section_8/part_3/spec/workplace_spec.rb +34 -0
- data/contents/questions/sequential_check/section_9/part_1/lib/answer.rb +9 -4
- data/contents/questions/sequential_check/section_9/part_1/lib/sentence.org +93 -4
- data/contents/questions/sequential_check/section_9/part_1/spec/workplace_spec.rb +14 -5
- data/contents/questions/sequential_check/section_9/part_2/lib/answer.rb +8 -5
- data/contents/questions/sequential_check/section_9/part_2/lib/sentence.org +92 -10
- data/contents/questions/sequential_check/section_9/part_2/spec/workplace_spec.rb +14 -5
- data/contents/questions/sequential_check/section_9/part_3/lib/answer.rb +7 -9
- data/contents/questions/sequential_check/section_9/part_3/lib/sentence.org +93 -4
- data/contents/questions/sequential_check/section_9/part_3/spec/workplace_spec.rb +14 -5
- data/lib/ruby_learner/sequential_main.rb +25 -12
- data/lib/ruby_learner/version.rb +1 -1
- metadata +26 -7
- data/contents/questions/sequential_check/section_6/part_4/lib/answer.rb +0 -9
- data/contents/questions/sequential_check/section_6/part_4/lib/sentence.org +0 -12
- data/contents/questions/sequential_check/section_6/part_4/lib/workplace.rb +0 -1
- data/contents/questions/sequential_check/section_6/part_4/spec/workplace_spec.rb +0 -9
@@ -1,15 +1,34 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
require "open3"
|
3
|
+
require "#{ENV['HOME']}/.ruby_learner/workshop/lib/workplace.rb"
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
is_instance_method = false
|
6
|
+
is_stdout_method = false
|
7
|
+
filename = "#{ENV['HOME']}/.ruby_learner/workshop/lib/workplace.rb"
|
8
|
+
|
9
|
+
RSpec.describe "class-check" do
|
10
|
+
it 'chesk Hello class contents' do
|
11
|
+
hello = Hello.new('sasaki')
|
12
|
+
expect{ hello.stdout }.to output("Hello, sasaki.\n").to_stdout
|
9
13
|
end
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
+
|
15
|
+
it 'check instance-method, return boolean' do
|
16
|
+
File.open(filename, "r") do |file|
|
17
|
+
file.each_line do |line|
|
18
|
+
is_instance_method = true if line.include?('Hello.new')
|
19
|
+
is_stdout_method = true if line.include?('.stdout')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
puts "ErrorMessage: you don't use class.new--methods." if !is_instance_method
|
24
|
+
puts "ErrorMessage: you don't use class.stdout--methods." if !is_stdout_method
|
25
|
+
|
26
|
+
expect( is_instance_method ).to eq(true)
|
27
|
+
expect( is_stdout_method ).to eq(true)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "given 'tanaka', return Hello, tanaka.\\n" do
|
31
|
+
stdout, stderr, status = Open3.capture3("ruby #{filename}")
|
32
|
+
expect { puts stdout }.to output("Hello, tanaka.\n").to_stdout
|
14
33
|
end
|
15
34
|
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
-課題-
|
2
|
+
Helloクラスを作成せよ.概要は以下に記す.
|
3
|
+
1. initializeメソッドを作成し,引数は文字列を受け取りインスタンス変数に格納する.
|
4
|
+
2. インスタンスメソッドとしてstdoutを作成し,1で用意したインスタンス変数を用いてputs "Hello, #{インスタンス変数}."のプログラムを書き加えよ.
|
5
|
+
|
6
|
+
作成したHelloクラスを用いて,「Hello, tanaka.」と表示せよ.
|
7
|
+
インスタンスの作成にはnewメソッドを用いること.
|
8
|
+
|
9
|
+
* Class
|
10
|
+
- Classとはオブジェクトの種類を表すものです.
|
11
|
+
Rubyでは文字列や数値もStringクラスやIntクラスです.実際に皆さんが文字列を作成する場合は,Stringクラスのインスタンスを作成していることになります.
|
12
|
+
- Classと一言にいってもその内容は少し複雑なので,ここでは基礎的な内容を解説します.
|
13
|
+
|
14
|
+
** インスタンス
|
15
|
+
- 作成したクラスを使用する場合に,作られるクラスの実体です.
|
16
|
+
その作られたクラスは一つのオブジェクトなので,そのオブジェクトをインスタンスと言います.
|
17
|
+
|
18
|
+
** 作成方法
|
19
|
+
- クラス名は必ず大文字で始めなければならない.
|
20
|
+
- 基本構造...class クラス名
|
21
|
+
クラスの定義(以下に説明する)
|
22
|
+
end
|
23
|
+
*** initializeメソッド...
|
24
|
+
- 機能...インスタンスが作成された時に最初に起動する処理を書く.引数はなくても良い.
|
25
|
+
- 使用方法...def initialize(引数)
|
26
|
+
処理
|
27
|
+
end
|
28
|
+
|
29
|
+
*** インスタンスメソッド
|
30
|
+
- 機能...インスタンスから参照できる関数.
|
31
|
+
- 使用方法...通常の関数定義と同じ.
|
32
|
+
|
33
|
+
*** アクセスメソッド
|
34
|
+
- 機能...インスタンス外部からインスタンス変数に関する操作を行える関数.
|
35
|
+
- 以下の参照と更新を同時に行えるメソッド.呼び出し方法は以下の2種類とも使うことができる.
|
36
|
+
attr_accessor :変数名
|
37
|
+
**** インスタンス変数を参照
|
38
|
+
- 作成方法1...def 変数名
|
39
|
+
@変数名
|
40
|
+
end
|
41
|
+
|
42
|
+
- 作成方法2...(クラス内のメソッド外に以下を記述)
|
43
|
+
attr_reader :変数名
|
44
|
+
|
45
|
+
- 呼び出し方法...作成済みのインスタンス.変数名
|
46
|
+
|
47
|
+
**** インスタンス変数の値を更新
|
48
|
+
- 作成方法1...def 変数名=(引数)
|
49
|
+
@変数名 = 引数
|
50
|
+
end
|
51
|
+
|
52
|
+
- 作成方法2...(クラス内のメソッド外に以下を記述)
|
53
|
+
attr_writer :変数名
|
54
|
+
|
55
|
+
- 呼び出し方法...作成済みのインスタンス.変数名 = 新しい値
|
56
|
+
|
57
|
+
*** インスタンス変数
|
58
|
+
- 機能...作成されたインスタンス内で共有の変数.
|
59
|
+
- 使用方法...@変数名 (initializeメソッド内で定義されることが多い)
|
60
|
+
|
61
|
+
*** 特別な変数self
|
62
|
+
- インスタンスメソッド内で,メソッドのレシーバ自身(クラス自身)を参照する為に使われる変数.
|
63
|
+
- 使用方法...self.クラス内のメソッドや変数
|
64
|
+
|
65
|
+
*** クラス変数
|
66
|
+
- クラスからインスタンス化された全てのオブジェクト内で共有する変数.
|
67
|
+
- 使用方法...@@変数名
|
68
|
+
|
69
|
+
*** メソッドの呼び出しを制限する
|
70
|
+
- クラス内で,インスタンス化した場合に呼び出し可能にするかどうかを制限することができる.
|
71
|
+
以下の3つの制御はインスタンスメソッドのdefの前にスペースを一つ開けて付け足すことで機能する.
|
72
|
+
- public...メソッドをインスタンスメソッドとして使えるように公開する.
|
73
|
+
- private...メソッドをレシーバを指定して呼び出せないようにする.
|
74
|
+
- protected...メソッドを同一のクラスであればインスタンスメソッドとして使えるようにする.
|
75
|
+
|
76
|
+
*** 継承
|
77
|
+
- 継承を行うことによって,既存のクラスには変更を加えずに,新しい機能を追加したり,部分的にカスタマイズしたりして新しいクラスを作ることができる.
|
78
|
+
- 使用方法...class 新しいクラス名 < 継承するクラス名
|
79
|
+
追加するメソッド
|
80
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
# section_8/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,34 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require "open3"
|
3
|
+
require "#{ENV['HOME']}/.ruby_learner/workshop/lib/workplace.rb"
|
4
|
+
|
5
|
+
is_instance_method = false
|
6
|
+
is_stdout_method = false
|
7
|
+
filename = "#{ENV['HOME']}/.ruby_learner/workshop/lib/workplace.rb"
|
8
|
+
|
9
|
+
RSpec.describe "class-check" do
|
10
|
+
it 'chesk Hello class contents' do
|
11
|
+
hello = Hello.new('sasaki')
|
12
|
+
expect{ hello.stdout }.to output("Hello, sasaki.\n").to_stdout
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'check instance-method, return boolean' do
|
16
|
+
File.open(filename, "r") do |file|
|
17
|
+
file.each_line do |line|
|
18
|
+
is_instance_method = true if line.include?('Hello.new')
|
19
|
+
is_stdout_method = true if line.include?('.stdout')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
puts "ErrorMessage: you don't use class.new--methods." if !is_instance_method
|
24
|
+
puts "ErrorMessage: you don't use class.stdout--methods." if !is_stdout_method
|
25
|
+
|
26
|
+
expect( is_instance_method ).to eq(true)
|
27
|
+
expect( is_stdout_method ).to eq(true)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "given 'tanaka', return Hello, tanaka.\\n" do
|
31
|
+
stdout, stderr, status = Open3.capture3("ruby #{filename}")
|
32
|
+
expect { puts stdout }.to output("Hello, tanaka.\n").to_stdout
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# section_8/part_3/answer.rb
|
2
|
+
# 8-3-class.rb
|
3
|
+
class Hello
|
4
|
+
def initialize(name)
|
5
|
+
@name = name
|
6
|
+
end
|
7
|
+
|
8
|
+
def stdout
|
9
|
+
puts "Hello, #{@name}."
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class AccessHello < Hello
|
14
|
+
attr_writer :name
|
15
|
+
end
|
16
|
+
|
17
|
+
access_hello = AccessHello.new('tanaka')
|
18
|
+
access_hello.stdout
|
19
|
+
access_hello.name = 'nakata'
|
20
|
+
access_hello.stdout
|
@@ -0,0 +1,80 @@
|
|
1
|
+
-課題-
|
2
|
+
与えられたクラス(Hello)を継承して新しくAccessHelloクラスを作成せよ.概要は以下に記す.
|
3
|
+
1. アクセスメソッドで@nameの値を変更できる機能を追加せよ.
|
4
|
+
|
5
|
+
AccessHelloクラスのインスタンスを作成し,引数に「tanaka」を与えた上でstdoutを用いて結果を出力せよ.
|
6
|
+
その後,アクセスメソッドを用いて引数の値を「nakata」に変更した上で再びstdoutを用いて結果を出力せよ.
|
7
|
+
|
8
|
+
* Class
|
9
|
+
- Classとはオブジェクトの種類を表すものです.
|
10
|
+
Rubyでは文字列や数値もStringクラスやIntクラスです.実際に皆さんが文字列を作成する場合は,Stringクラスのインスタンスを作成していることになります.
|
11
|
+
- Classと一言にいってもその内容は少し複雑なので,ここでは基礎的な内容を解説します.
|
12
|
+
|
13
|
+
** インスタンス
|
14
|
+
- 作成したクラスを使用する場合に,作られるクラスの実体です.
|
15
|
+
その作られたクラスは一つのオブジェクトなので,そのオブジェクトをインスタンスと言います.
|
16
|
+
|
17
|
+
** 作成方法
|
18
|
+
- クラス名は必ず大文字で始めなければならない.
|
19
|
+
- 基本構造...class クラス名
|
20
|
+
クラスの定義(以下に説明する)
|
21
|
+
end
|
22
|
+
*** initializeメソッド...
|
23
|
+
- 機能...インスタンスが作成された時に最初に起動する処理を書く.引数はなくても良い.
|
24
|
+
- 使用方法...def initialize(引数)
|
25
|
+
処理
|
26
|
+
end
|
27
|
+
|
28
|
+
*** インスタンスメソッド
|
29
|
+
- 機能...インスタンスから参照できる関数.
|
30
|
+
- 使用方法...通常の関数定義と同じ.
|
31
|
+
|
32
|
+
*** アクセスメソッド
|
33
|
+
- 機能...インスタンス外部からインスタンス変数に関する操作を行える関数.
|
34
|
+
- 以下の参照と更新を同時に行えるメソッド.呼び出し方法は以下の2種類とも使うことができる.
|
35
|
+
attr_accessor :変数名
|
36
|
+
**** インスタンス変数を参照
|
37
|
+
- 作成方法1...def 変数名
|
38
|
+
@変数名
|
39
|
+
end
|
40
|
+
|
41
|
+
- 作成方法2...(クラス内のメソッド外に以下を記述)
|
42
|
+
attr_reader :変数名
|
43
|
+
|
44
|
+
- 呼び出し方法...作成済みのインスタンス.変数名
|
45
|
+
|
46
|
+
**** インスタンス変数の値を更新
|
47
|
+
- 作成方法1...def 変数名=(引数)
|
48
|
+
@変数名 = 引数
|
49
|
+
end
|
50
|
+
|
51
|
+
- 作成方法2...(クラス内のメソッド外に以下を記述)
|
52
|
+
attr_writer :変数名
|
53
|
+
|
54
|
+
- 呼び出し方法...作成済みのインスタンス.変数名 = 新しい値
|
55
|
+
|
56
|
+
|
57
|
+
*** インスタンス変数
|
58
|
+
- 機能...作成されたインスタンス内で共有の変数.
|
59
|
+
- 使用方法...@変数名 (initializeメソッド内で定義されることが多い)
|
60
|
+
|
61
|
+
*** 特別な変数self
|
62
|
+
- インスタンスメソッド内で,メソッドのレシーバ自身(クラス自身)を参照する為に使われる変数.
|
63
|
+
- 使用方法...self.クラス内のメソッドや変数
|
64
|
+
|
65
|
+
*** クラス変数
|
66
|
+
- クラスからインスタンス化された全てのオブジェクト内で共有する変数.
|
67
|
+
- 使用方法...@@変数名
|
68
|
+
|
69
|
+
*** メソッドの呼び出しを制限する
|
70
|
+
- クラス内で,インスタンス化した場合に呼び出し可能にするかどうかを制限することができる.
|
71
|
+
以下の3つの制御はインスタンスメソッドのdefの前にスペースを一つ開けて付け足すことで機能する.
|
72
|
+
- public...メソッドをインスタンスメソッドとして使えるように公開する.
|
73
|
+
- private...メソッドをレシーバを指定して呼び出せないようにする.
|
74
|
+
- protected...メソッドを同一のクラスであればインスタンスメソッドとして使えるようにする.
|
75
|
+
|
76
|
+
*** 継承
|
77
|
+
- 継承を行うことによって,既存のクラスには変更を加えずに,新しい機能を追加したり,部分的にカスタマイズしたりして新しいクラスを作ることができる.
|
78
|
+
- 使用方法...class 新しいクラス名 < 継承するクラス名
|
79
|
+
追加するメソッド
|
80
|
+
end
|
@@ -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
|