hello,
Im still working on ruby koans. Now I have to do some sandwhich code.
The exercise looks like this :
require File.expand_path(File.dirname(FILE) + ‘/edgecase’)
class AboutSandwichCode < EdgeCase::Koan
def count_lines(file_name) file = open(file_name) count = 0 while line = file.gets count += 1 end count ensure file.close if file end
def test_counting_lines assert_equal 4, count_lines(“example_file.txt”) end
------------------------------------------------------------------
def find_line(file_name) file = open(file_name) while line = file.gets return line if line.match(/e/) end ensure file.close if file end
def test_finding_lines assert_equal “test\n”, find_line(“example_file.txt”) end