lib/procemon/mpatch/file.rb in procemon-0.1.1 vs lib/procemon/mpatch/file.rb in procemon-0.1.3

- old
+ new

@@ -1,6 +1,8 @@ class File + + # create a file, if not exsist create file, and dir if needed def self.create(route_name ,filemod="w",string_data=String.new) begin #file_name generate if !route_name.to_s.split(File::SEPARATOR).last.nil? || route_name.to_s.split(File::SEPARATOR).last != '' @@ -43,6 +45,27 @@ rescue Exception => ex puts ex end end + + # start read the file object on each line + # optionable an integer value to start read line at + # compatible with mac (i am linux user, so not tested) + def each_line_from(start_at=1,&block) + unless [Integer,Fixnum,Bignum].include?(start_at.class) + raise ArgumentError, "invalid line index" + end + begin + line_num= 1 + text= self.read + text.gsub!(/\r\n?/, "\n") + text.each_line do |*line| + if line_num >= start_at + block.call *line + end + line_num += 1 + end + end + end + end \ No newline at end of file