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