mirror of
https://github.com/edgecase/ruby_koans.git
synced 2026-04-15 07:23:19 -04:00
Cleaned up some messy File housekeeping.
This commit is contained in:
@@ -78,16 +78,13 @@ class AboutIteration < EdgeCase::Koan
|
|||||||
assert_equal __, result
|
assert_equal __, result
|
||||||
|
|
||||||
# Files act like a collection of lines
|
# Files act like a collection of lines
|
||||||
file = File.open("example_file.txt")
|
upcase_lines = File.open("example_file.txt") do |file|
|
||||||
upcase_lines = file.map { |line| line.strip.upcase }
|
file.map { |line| line.strip.upcase }
|
||||||
|
end
|
||||||
assert_equal __, upcase_lines
|
assert_equal __, upcase_lines
|
||||||
|
|
||||||
# NOTE: You can create your own collections that work with each,
|
# NOTE: You can create your own collections that work with each,
|
||||||
# map, select, etc.
|
# map, select, etc.
|
||||||
ensure
|
|
||||||
# Arg, this is ugly.
|
|
||||||
# We will figure out how to fix this later.
|
|
||||||
file.close if file
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -78,16 +78,13 @@ class AboutIteration < EdgeCase::Koan
|
|||||||
assert_equal __([11, 12, 13]), result
|
assert_equal __([11, 12, 13]), result
|
||||||
|
|
||||||
# Files act like a collection of lines
|
# Files act like a collection of lines
|
||||||
file = File.open("example_file.txt")
|
upcase_lines = File.open("example_file.txt") do |file|
|
||||||
upcase_lines = file.map { |line| line.strip.upcase }
|
file.map { |line| line.strip.upcase }
|
||||||
|
end
|
||||||
assert_equal __(["THIS", "IS", "A", "TEST"]), upcase_lines
|
assert_equal __(["THIS", "IS", "A", "TEST"]), upcase_lines
|
||||||
|
|
||||||
# NOTE: You can create your own collections that work with each,
|
# NOTE: You can create your own collections that work with each,
|
||||||
# map, select, etc.
|
# map, select, etc.
|
||||||
ensure
|
|
||||||
# Arg, this is ugly.
|
|
||||||
# We will figure out how to fix this later.
|
|
||||||
file.close if file
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user