Skip to content

Commit 5d06a3a

Browse files
committed
Update koans
1 parent aa768eb commit 5d06a3a

9 files changed

+49
-24
lines changed

koans/README.rdoc

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
= Neo Ruby Koans
1+
= Ruby Koans
22

33
The Ruby Koans walk you along the path to enlightenment in order to learn Ruby.
44
The goal is to learn the Ruby language, syntax, structure, and some common
@@ -98,7 +98,7 @@ The very first time you run the koans you will see the following output:
9898
path_to_enlightenment.rb:38
9999

100100
mountains are merely mountains
101-
your path thus far [X_________________________________________________] 0/280
101+
your path thus far [X_________________________________________________] 0/280 (0%)
102102

103103
You have come to your first stage. Notice it is telling you where to look for
104104
the first solution:
@@ -149,7 +149,7 @@ Install the Ruby gem (library) called +observr+ and then ask it to
149149
rake
150150
# decide to run rake automatically from now on as you edit
151151
gem install observr
152-
observr ./koans/koans.watchr
152+
observr ./koans.watchr
153153

154154
== Inspiration
155155

@@ -179,7 +179,7 @@ Brian Marick's fantastic guide for beginners Everyday Scripting with Ruby ::
179179

180180
Author :: Jim Weirich <jim@neo.org>
181181
Author :: Joe O'Brien <joe@objo.com>
182-
Issue Tracker :: http://www.pivotaltracker.com/projects/48111
182+
Issue Tracker :: https://github.com/edgecase/ruby_koans/issues
183183
Requires :: Ruby 1.8.x or later and Rake (any recent version)
184184

185185
= License

koans/about_array_assignment.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_parallel_assignments_with_splat_operator
2424
assert_equal __, last_name
2525
end
2626

27-
def test_parallel_assignments_with_too_few_variables
27+
def test_parallel_assignments_with_too_few_values
2828
first_name, last_name = ["Cher"]
2929
assert_equal __, first_name
3030
assert_equal __, last_name

koans/about_hashes.rb

+10
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,14 @@ def test_default_value_with_block
113113
assert_equal __, hash[:two]
114114
assert_equal __, hash[:three]
115115
end
116+
117+
def test_default_value_attribute
118+
hash = Hash.new
119+
120+
assert_equal __, hash[:some_key]
121+
122+
hash.default = 'peanut'
123+
124+
assert_equal __, hash[:some_key]
125+
end
116126
end

koans/about_iteration.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def as_name(name)
1414
end
1515
end
1616

17-
in_ruby_version("1.9", "2") do
17+
in_ruby_version("1.9", "2", "3") do
1818
def as_name(name)
1919
name.to_sym
2020
end

koans/about_keyword_arguments.rb

+15-3
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,20 @@ def test_keyword_arguments_with_wrong_number_of_arguments
2424
assert_match(/__/, exception.message)
2525
end
2626

27-
# THINK ABOUT IT:
28-
#
29-
# Keyword arguments always have a default value, making them optional to the caller
27+
def method_with_mandatory_keyword_arguments(one:, two: 'two')
28+
[one, two]
29+
end
30+
31+
def test_mandatory_keyword_arguments
32+
assert_equal __, method_with_mandatory_keyword_arguments(one: 'one')
33+
assert_equal __, method_with_mandatory_keyword_arguments(two: 2, one: 1)
34+
end
35+
36+
def test_mandatory_keyword_arguments_without_mandatory_argument
37+
exception = assert_raise(___) do
38+
method_with_mandatory_keyword_arguments
39+
end
40+
assert_match(/__/, exception.message)
41+
end
3042

3143
end

koans/about_open_classes.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ def test_after_reopening_dogs_can_both_wag_and_bark
3030
# ------------------------------------------------------------------
3131

3232
class ::Integer
33-
def even?
34-
(self % 2) == 0
33+
def answer_to_life_universe_and_everything?
34+
self == 42
3535
end
3636
end
3737

3838
def test_even_existing_built_in_classes_can_be_reopened
39-
assert_equal __, 1.even?
40-
assert_equal __, 2.even?
39+
assert_equal __, 1.answer_to_life_universe_and_everything?
40+
assert_equal __, 42.answer_to_life_universe_and_everything?
4141
end
4242

4343
# NOTE: To understand why we need the :: before Integer, you need to

koans/about_strings.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def test_in_older_ruby_single_characters_are_represented_by_integers
159159
end
160160
end
161161

162-
in_ruby_version("1.9", "2") do
162+
in_ruby_version("1.9", "2", "3") do
163163
def test_in_modern_ruby_single_characters_are_represented_by_strings
164164
assert_equal __, ?a
165165
assert_equal __, ?a == 97

koans/neo.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def ____(method=nil)
7070
end
7171
end
7272

73-
in_ruby_version("1.9", "2") do
73+
in_ruby_version("1.9", "2", "3") do
7474
public :method_missing
7575
end
7676
end
@@ -218,15 +218,15 @@ def initialize
218218

219219
def add_progress(prog)
220220
@_contents = nil
221-
exists = File.exists?(PROGRESS_FILE_NAME)
221+
exists = File.exist?(PROGRESS_FILE_NAME)
222222
File.open(PROGRESS_FILE_NAME,'a+') do |f|
223223
f.print "#{',' if exists}#{prog}"
224224
end
225225
end
226226

227227
def progress
228228
if @_contents.nil?
229-
if File.exists?(PROGRESS_FILE_NAME)
229+
if File.exist?(PROGRESS_FILE_NAME)
230230
File.open(PROGRESS_FILE_NAME,'r') do |f|
231231
@_contents = f.read.to_s.gsub(/\s/,'').split(',')
232232
end

koans/path_to_enlightenment.rb

+10-7
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
$LOAD_PATH << File.dirname(__FILE__)
44

55
require 'about_asserts'
6-
require 'about_nil'
7-
require 'about_objects'
6+
require 'about_true_and_false'
7+
require 'about_strings'
8+
require 'about_symbols'
89
require 'about_arrays'
910
require 'about_array_assignment'
11+
require 'about_objects'
12+
require 'about_nil'
1013
require 'about_hashes'
11-
require 'about_strings'
12-
require 'about_symbols'
13-
require 'about_regular_expressions'
1414
require 'about_methods'
15-
in_ruby_version("2") do
15+
in_ruby_version("2", "3") do
1616
require 'about_keyword_arguments'
1717
end
1818
require 'about_constants'
19+
require 'about_regular_expressions'
1920
require 'about_control_statements'
20-
require 'about_true_and_false'
2121
require 'about_triangle_project'
2222
require 'about_exceptions'
2323
require 'about_triangle_project_2'
@@ -38,4 +38,7 @@
3838
in_ruby_version("jruby") do
3939
require 'about_java_interop'
4040
end
41+
in_ruby_version("2.7") do
42+
require 'about_pattern_matching'
43+
end
4144
require 'about_extra_credit'

0 commit comments

Comments
 (0)