Sha256: 8c865221124a9da0f23a74cafe635ec70059550668127a97f8c8073fd052d8ad
Contents?: true
Size: 892 Bytes
Versions: 20
Compression:
Stored size: 892 Bytes
Contents
# Reads in a file, removes blank lines and remarks # (lines starting with '#') and then returns # an array of all the remaining lines. # def File.read_list(filepath, chomp_string='') farr = nil farr = File.read(filepath).split("\n") farr.collect! { |line| l = line.strip.chomp(chomp_string) (l.empty? or l[0,1] == '#') ? nil : l } farr.compact end # _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # =begin test require 'test/unit' # mock behavior for file access class File def self.mock_read( content ) @content = content end def self.read( fpath ) @content end end class TC_READ_LIST < Test::Unit::TestCase def test_read_list f = File.mock_read("A\nB\nC") s = File.read_list( f ) r = ['A','B','C'] assert_equal( r, s ) end end =end
Version data entries
20 entries across 20 versions & 1 rubygems