Displaying 1 result from an estimated 1 matches for "count_lin".
Did you mean:
count_if
2012 Sep 23
1
ruby koans don't understand the principle sandwhich code
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
# ---------------------------------------------...