mirror of
https://github.com/edgecase/ruby_koans.git
synced 2026-04-21 01:03:20 -04:00
Updated koans from source.
This commit is contained in:
@@ -78,13 +78,26 @@ class AboutIteration < EdgeCase::Koan
|
||||
assert_equal __, result
|
||||
|
||||
# Files act like a collection of lines
|
||||
upcase_lines = File.open("example_file.txt") do |file|
|
||||
file.map { |line| line.strip.upcase }
|
||||
File.open("example_file.txt") do |file|
|
||||
upcase_lines = file.map { |line| line.strip.upcase }
|
||||
assert_equal __, upcase_lines
|
||||
end
|
||||
assert_equal __, upcase_lines
|
||||
|
||||
# NOTE: You can create your own collections that work with each,
|
||||
# map, select, etc.
|
||||
end
|
||||
|
||||
# Bonus Question: In the previous koan, we saw the construct:
|
||||
#
|
||||
# File.open(filename) do |file|
|
||||
# # code to read 'file'
|
||||
# end
|
||||
#
|
||||
# Why did we do it that way instead of the following?
|
||||
#
|
||||
# file = File.open(filename)
|
||||
# # code to read 'file'
|
||||
#
|
||||
# When you get to the "AboutSandwichCode" koan, recheck your answer.
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user