From b0e34a90e093733ad84c3fe90c32e0e7de2a36dd Mon Sep 17 00:00:00 2001 From: Greg Mefford Date: Sun, 12 Sep 2010 17:07:22 -0400 Subject: [PATCH] Cleaned up some messy File housekeeping. --- koans/about_iteration.rb | 9 +++------ src/about_iteration.rb | 9 +++------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/koans/about_iteration.rb b/koans/about_iteration.rb index 608f1e9..83b5a28 100644 --- a/koans/about_iteration.rb +++ b/koans/about_iteration.rb @@ -78,16 +78,13 @@ class AboutIteration < EdgeCase::Koan assert_equal __, result # Files act like a collection of lines - file = File.open("example_file.txt") - upcase_lines = file.map { |line| line.strip.upcase } + upcase_lines = File.open("example_file.txt") do |file| + file.map { |line| line.strip.upcase } + end assert_equal __, upcase_lines # NOTE: You can create your own collections that work with each, # map, select, etc. - ensure - # Arg, this is ugly. - # We will figure out how to fix this later. - file.close if file end end diff --git a/src/about_iteration.rb b/src/about_iteration.rb index 4c4daa6..e995a5e 100644 --- a/src/about_iteration.rb +++ b/src/about_iteration.rb @@ -78,16 +78,13 @@ class AboutIteration < EdgeCase::Koan assert_equal __([11, 12, 13]), result # Files act like a collection of lines - file = File.open("example_file.txt") - upcase_lines = file.map { |line| line.strip.upcase } + upcase_lines = File.open("example_file.txt") do |file| + file.map { |line| line.strip.upcase } + end assert_equal __(["THIS", "IS", "A", "TEST"]), upcase_lines # NOTE: You can create your own collections that work with each, # map, select, etc. - ensure - # Arg, this is ugly. - # We will figure out how to fix this later. - file.close if file end end