battleroom 0.0.86 → 0.0.87
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/battleroom/battleroom_machinery.rb +1 -1
- data/lib/battleroom/data/method_questions.rb +43 -2
- data/lib/battleroom/data/variable_assignment_questions.rb +1 -1
- data/lib/battleroom/models/method_definition_question.rb +85 -85
- data/lib/battleroom/models/method_invocation_question.rb +75 -75
- data/lib/battleroom.rb +5 -5
- metadata +1 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea6eacbcacf28f4bca5940747bf9f4da36ef5d13
|
4
|
+
data.tar.gz: 21b8d9c2b78ab1a42fef3cc600288fe854213c3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3eb408861d7139e022230ccda9065e86f532a826c6d23b3d7f1b8941ac1e6c407f61b5b5b5b37069c6259706a793d124908c3187166ae80e510aa8f0de53f65f
|
7
|
+
data.tar.gz: 566149a7846b4534eb531a3480c95575a89e294319e2316c67681837d5ed555cc385690adce577519400bb121abac2c3ea1fb195acd69300ff090309cb3672b4
|
@@ -30,7 +30,7 @@ module BattleroomMachinery
|
|
30
30
|
battleprint '1. Working with Variables'
|
31
31
|
battleprint '2. Accessing Values in Arrays and Hashes'
|
32
32
|
battleprint '3. Adding Values to Arrays and Hashes'
|
33
|
-
battleprint '4. Working with Methods'
|
33
|
+
# battleprint '4. Working with Methods'
|
34
34
|
battleprint "Q. Quit\r\n\n"
|
35
35
|
end
|
36
36
|
|
@@ -6,6 +6,12 @@ volume_arg_three = rand(1..9)
|
|
6
6
|
double_arg = rand(2..50)
|
7
7
|
square_arg = rand(2..12)
|
8
8
|
cube_arg = rand(2..5)
|
9
|
+
meters_to_centimeters_arg = rand(11..99)
|
10
|
+
grams_to_milligrams_arg = rand(3..11)
|
11
|
+
convert_bytes_to_bits_arg = ((6..11).to_a + [100, 1000]).sample
|
12
|
+
|
13
|
+
# values explicitly chosen to avoid values that would result in imprecise floating point arithmetic
|
14
|
+
kilograms_to_pounds_arg = [2, 4, 10, 20, 30, 1000].shuffle.sample
|
9
15
|
|
10
16
|
METHOD_QUESTONS = [
|
11
17
|
{
|
@@ -53,14 +59,14 @@ METHOD_QUESTONS = [
|
|
53
59
|
{
|
54
60
|
method_name: "square",
|
55
61
|
arg_count: 1,
|
56
|
-
spec: "returns its lone argument to the
|
62
|
+
spec: "returns its lone argument to the second power",
|
57
63
|
eval_string: "square(#{square_arg})",
|
58
64
|
eval_answer: square_arg ** 2
|
59
65
|
},
|
60
66
|
{
|
61
67
|
method_name: "cube",
|
62
68
|
arg_count: 1,
|
63
|
-
spec: "returns its lone argument to the
|
69
|
+
spec: "returns its lone argument to the third power",
|
64
70
|
eval_string: "cube(#{cube_arg})",
|
65
71
|
eval_answer: cube_arg ** 3
|
66
72
|
},
|
@@ -78,4 +84,39 @@ METHOD_QUESTONS = [
|
|
78
84
|
eval_string: "celcius_to_kelvin(#{square_arg})",
|
79
85
|
eval_answer: square_arg + 273.15
|
80
86
|
},
|
87
|
+
{
|
88
|
+
method_name: "kilograms_to_pounds",
|
89
|
+
arg_count: 1,
|
90
|
+
spec: "returns its lone argument multiplied by the Float value " + "\e[0;33;49m2.2\e[0m",
|
91
|
+
eval_string: "kilograms_to_pounds(#{kilograms_to_pounds_arg})",
|
92
|
+
eval_answer: kilograms_to_pounds_arg * 2.2
|
93
|
+
},
|
94
|
+
{
|
95
|
+
method_name: "meters_to_centimeters",
|
96
|
+
arg_count: 1,
|
97
|
+
spec: "returns its lone argument multiplied by the Fixnum value " + "\e[0;33;49m100\e[0m",
|
98
|
+
eval_string: "meters_to_centimeters(#{kilograms_to_pounds_arg})",
|
99
|
+
eval_answer: kilograms_to_pounds_arg * 100
|
100
|
+
},
|
101
|
+
{
|
102
|
+
method_name: "grams_to_milligrams",
|
103
|
+
arg_count: 1,
|
104
|
+
spec: "returns its lone argument multiplied by the Fixnum value 1000",
|
105
|
+
eval_string: "grams_to_milligrams(#{grams_to_milligrams_arg})",
|
106
|
+
eval_answer: grams_to_milligrams_arg * 1000
|
107
|
+
},
|
108
|
+
# {
|
109
|
+
# method_name: "convert_weeks_to_minutes",
|
110
|
+
# arg_count: 1,
|
111
|
+
# spec: "returns its lone argument multiplied the product of the Fixnum values 7, 24, and 60",
|
112
|
+
# eval_string: "grams_to_milligrams(#{grams_to_milligrams_arg})",
|
113
|
+
# eval_answer: grams_to_milligrams_arg * 1000
|
114
|
+
# },
|
115
|
+
{
|
116
|
+
method_name: "convert_bytes_to_bits",
|
117
|
+
arg_count: 1,
|
118
|
+
spec: "returns its lone argument multiplied by the Fixnum value 8",
|
119
|
+
eval_string: "convert_bytes_to_bits(#{convert_bytes_to_bits_arg})",
|
120
|
+
eval_answer: convert_bytes_to_bits_arg * 8
|
121
|
+
},
|
81
122
|
].shuffle
|
@@ -1,102 +1,102 @@
|
|
1
1
|
require_relative '../data/method_questions'
|
2
2
|
require_relative './question'
|
3
3
|
|
4
|
-
class MethodDefinitionQuestion < Question
|
4
|
+
# class MethodDefinitionQuestion < Question
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
# attr_accessor :method_name, :arg_count, :spec, :eval_string, :eval_answer,
|
7
|
+
# :return_value, :user_answer_verified
|
8
8
|
|
9
|
-
|
9
|
+
# @questions = METHOD_QUESTONS.shuffle
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
# def initialize(scope)
|
12
|
+
# super(scope)
|
13
|
+
# @method_name = data[:method_name]
|
14
|
+
# @arg_count = data[:arg_count]
|
15
|
+
# @spec = data[:spec]
|
16
|
+
# @eval_string = data[:eval_string]
|
17
|
+
# @eval_answer = data[:eval_answer]
|
18
|
+
# @input_mechanism = 'pry'
|
19
|
+
# print_prompt
|
20
|
+
# evaluate_method_definition_input
|
21
|
+
# end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
# def print_prompt
|
24
|
+
# battleprint('Define a method called '.blue + method_name.yellow + ' that takes '.blue + arg_count.to_s.yellow + " argument(s) and #{spec}.\n".blue)
|
25
|
+
# end
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
# def handle_name_error_exceptions(error, user_submission)
|
28
|
+
# if user_submission.include?('def') == false
|
29
|
+
# print_no_method_error_prompt
|
30
|
+
# else
|
31
|
+
# print_colorized_error_prompt(error)
|
32
|
+
# end
|
33
|
+
# end
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
# def handle_incorrect_method_definition(return_value)
|
36
|
+
# battleprint "\nWhen invoking your method via ".red + eval_string + ", your method returned #{return_value || 'nil'}. It should have returned #{eval_answer}. Try again.\n".red
|
37
|
+
# end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
# def print_puts_explanation
|
40
|
+
# battleprint 'The last line of your method definition uses Ruby\'s "puts" method. The "puts" method is helpful for logging errors and statuses to the console, but its actual '.red + "return".red.underline + " value is always nil, and thus your method returns nil. Try again, this time without using \"puts\".\n".red
|
41
|
+
# end
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
# def print_no_method_error_prompt
|
44
|
+
# battleprint "\nYou just trigged a common Ruby error that reads: \n".red
|
45
|
+
# battleprint "\tundefined method \'WHATEVER_METHOD_YOU_TRIED_TO_INVOKE\'\n".green
|
46
|
+
# battleprint "Basically, you tried to use a method before you defined it, and Ruby said, \"You haven't told me how to do that yet.\" To let Ruby know that you're defining a method, you'll use the the \"def\" keyword, followed by the desired method name, and in many cases an optional list of arguments between parentheses. Once you've finished writing the method's inner code, you'll let Ruby know that your method definition is finished by using the \"end\" keyword.\n".red
|
47
|
+
# end
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
49
|
+
# def fresh_binding
|
50
|
+
# binding
|
51
|
+
# end
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
53
|
+
# def print_wrong_method_error(error, user_submission)
|
54
|
+
# definition_pattern = Regexp.new("def\s*#{method_name}")
|
55
|
+
# if user_submission.match(definition_pattern)
|
56
|
+
# handle_incorrect_method_definition(user_submission)
|
57
|
+
# else
|
58
|
+
# battleprint "\nYou defined the wrong method, probably as the result of a mispelling. Try again.".red
|
59
|
+
# end
|
60
|
+
# end
|
61
61
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
62
|
+
# def print_argument_error_prompt(e)
|
63
|
+
# e.message.match(/wrong number of arguments \((\d) for (\d)\)/)
|
64
|
+
# passed_arg_count = $1.to_i
|
65
|
+
# expected_arg_count = $2.to_i
|
66
|
+
# battleprint "\nLooks like you defined #{method_name} to take #{expected_arg_count} argument(s), when it should take #{arg_count}. Try again.\n".red
|
67
|
+
# end
|
68
68
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
69
|
+
# def clean_eval_scope_of_method_definition
|
70
|
+
# if evaluation_scope.eval "respond_to?(:#{method_name}, true)"
|
71
|
+
# evaluation_scope.eval 'Object.class_eval("remove_method :' + method_name + '")'
|
72
|
+
# end
|
73
|
+
# end
|
74
74
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
75
|
+
# def evaluate_method_definition_input
|
76
|
+
# enter_evaluation_loop do |user_submission|
|
77
|
+
# begin
|
78
|
+
# clean_eval_scope_of_method_definition
|
79
|
+
# # I want to make sure that the user's method isn't invoked if it uses the puts method
|
80
|
+
# if user_submission.include?('puts')
|
81
|
+
# print_puts_explanation
|
82
|
+
# else
|
83
|
+
# evaluation_scope.eval(user_submission)
|
84
|
+
# return_value = evaluation_scope.eval(eval_string)
|
85
|
+
# if (return_value == eval_answer)
|
86
|
+
# self.user_answer_verified = user_submission
|
87
|
+
# true
|
88
|
+
# else
|
89
|
+
# handle_incorrect_method_definition(return_value)
|
90
|
+
# end
|
91
|
+
# end
|
92
|
+
# rescue ArgumentError => e
|
93
|
+
# print_argument_error_prompt(e)
|
94
|
+
# rescue NoMethodError => e
|
95
|
+
# print_wrong_method_error(e, user_submission)
|
96
|
+
# rescue NameError => e
|
97
|
+
# handle_name_error_exceptions(e, user_submission)
|
98
|
+
# end
|
99
|
+
# end
|
100
|
+
# end
|
101
101
|
|
102
|
-
end
|
102
|
+
# end
|
@@ -1,90 +1,90 @@
|
|
1
1
|
require_relative './follow_up_question'
|
2
2
|
|
3
|
-
class MethodInvocationQuestion < FollowUpQuestion
|
3
|
+
# class MethodInvocationQuestion < FollowUpQuestion
|
4
4
|
|
5
|
-
|
5
|
+
# attr_reader :desired_answer_formatted, :desired_answer_class_formatted
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
# def initialize(evaluation_scope, question_to_follow_up_on)
|
8
|
+
# super(evaluation_scope, question_to_follow_up_on)
|
9
|
+
# @desired_answer_formatted = format_value_for_stdout_and_eval(original_question.eval_answer)
|
10
|
+
# @desired_answer_class_formatted = format_class_for_output(original_question.eval_answer.class)
|
11
|
+
# print_method_invocation_prompt
|
12
|
+
# evaluate_user_input
|
13
|
+
# end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
# def format_method_definition_for_stdout
|
16
|
+
# code = CodeRay.scan($input, :ruby)
|
17
|
+
# ansi_prepped_string = code.term
|
18
|
+
# indent_all_lines_for_stdout(ansi_prepped_string)
|
19
|
+
# end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
# def print_method_invocation_prompt
|
22
|
+
# battleprint "You now have the method defined below at your disposal.\n".blue
|
23
|
+
# battleprint format_method_definition_for_stdout
|
24
|
+
# battleprint "\nInvoke the '#{original_question.method_name}' method such that it returns the ".blue + desired_answer_class_formatted.blue + " value ".blue + desired_answer_formatted.yellow + ".\n".blue
|
25
|
+
# end
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
# def print_no_method_error_prompt
|
28
|
+
# battleprint "\nYou just trigged a common Ruby error that reads: \n".red
|
29
|
+
# battleprint "\tundefined local variable or method \'WHATEVER_METHOD_YOU_TRIED_TO_INVOKE\'\n".green
|
30
|
+
# battleprint "Basically, you tried to invoke a method that doesn't exist. Try again.\n".red
|
31
|
+
# end
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
33
|
+
# def print_name_error_prompt(error, user_submission)
|
34
|
+
# battleprint "\nYou just triggered a common Ruby error that reads:\n".red
|
35
|
+
# battleprint "\tNameError: #{error.message}\n".green
|
36
|
+
# referenced_variable = isolate_variable_name_from_name_error(error)
|
37
|
+
# parameters = isolate_argument_names_from_method_def
|
38
|
+
# if parameters.find { |parameter| parameter == referenced_variable }
|
39
|
+
# battleprint "Looks like the variable you referenced was one of the argument names in your method #{'definition'.red.underline}. The arguments in method definitions are just placeholders for whatever values end up getting passed in when the method is called. Think on this for a moment before trying again.\n".red
|
40
|
+
# else
|
41
|
+
# battleprint "Basically, you're referencing a variable, \"#{referenced_variable}\", that hasn't been assigned a value.\n".red
|
42
|
+
# end
|
43
|
+
# end
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
# def isolate_variable_name_from_name_error(error)
|
46
|
+
# error.name.to_s
|
47
|
+
# end
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
49
|
+
# def print_argument_error_prompt(e)
|
50
|
+
# e.message.match(/wrong number of arguments \((\d) for (\d)\)/)
|
51
|
+
# passed_arg_count = $1.to_i
|
52
|
+
# expected_arg_count = $2.to_i
|
53
|
+
# battleprint "You just triggered a common Ruby error that reads:\n".red
|
54
|
+
# battleprint "\tArgumentError: #{e.message}\n".green
|
55
|
+
# battleprint "Basically, you defined the '#{original_question.method_name}' method to expect #{expected_arg_count} argument(s), and you're only passing it #{passed_arg_count}. Try again.\n".red
|
56
|
+
# end
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
58
|
+
# def isolate_argument_names_from_method_def
|
59
|
+
# isolate_parameter_list_string_from_method_def.scan(/([^,\s]+)+/x).flatten
|
60
|
+
# end
|
61
61
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
62
|
+
# def isolate_parameter_list_string_from_method_def
|
63
|
+
# original_question.user_answer_verified.match /\((.+)\)/
|
64
|
+
# $1
|
65
|
+
# end
|
66
66
|
|
67
|
-
|
68
|
-
|
69
|
-
|
67
|
+
# def print_incorrect_input_prompt(return_from_eval)
|
68
|
+
# battleprint "Your code returned the #{format_class_for_output(return_from_eval.class)} value #{return_from_eval.to_s} when it should have returned the #{desired_answer_class_formatted} value #{desired_answer_formatted}. Try again.".red
|
69
|
+
# end
|
70
70
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
71
|
+
# def evaluate_user_input
|
72
|
+
# enter_evaluation_loop do |user_submission|
|
73
|
+
# begin
|
74
|
+
# return_from_eval = original_question.evaluation_scope.eval(user_submission)
|
75
|
+
# if return_from_eval == original_question.eval_answer
|
76
|
+
# true
|
77
|
+
# else
|
78
|
+
# print_incorrect_input_prompt(return_from_eval)
|
79
|
+
# end
|
80
|
+
# rescue NoMethodError => e
|
81
|
+
# print_no_method_error_prompt
|
82
|
+
# rescue NameError => e
|
83
|
+
# print_name_error_prompt(e, user_submission)
|
84
|
+
# rescue ArgumentError => e
|
85
|
+
# print_argument_error_prompt(e)
|
86
|
+
# end
|
87
|
+
# end
|
88
|
+
# end
|
89
89
|
|
90
|
-
end
|
90
|
+
# end
|
data/lib/battleroom.rb
CHANGED
@@ -28,12 +28,12 @@ loop do
|
|
28
28
|
5.times do
|
29
29
|
q = [ArrayAssignmentQuestion.new(b), HashAssignmentQuestion.new(b)].sample
|
30
30
|
end
|
31
|
+
# when '4'
|
32
|
+
# 5.times do
|
33
|
+
# q = MethodDefinitionQuestion.new(b)
|
34
|
+
# follow_up_question = MethodInvocationQuestion.new(b, q)
|
35
|
+
# end
|
31
36
|
when '4'
|
32
|
-
5.times do
|
33
|
-
q = MethodDefinitionQuestion.new(b)
|
34
|
-
follow_up_question = MethodInvocationQuestion.new(b, q)
|
35
|
-
end
|
36
|
-
when '5'
|
37
37
|
5.times { NestedDataStructureAccessQuestion.new(b) }
|
38
38
|
else
|
39
39
|
battleprint 'You entered a non-option. Try again.'.red
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: battleroom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.87
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Travis Vander Hoop
|
@@ -80,20 +80,6 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0.10'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: pry-byebug
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '2.0'
|
90
|
-
type: :runtime
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '2.0'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: coderay
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|