Browse | Submit A New Snippet | Create A Package

 

GenLib

Type:
Class
Category:
File Management
License:
Ruby License
Language:
Ruby
 
Description:
A small Ruby file generating class. You must include a file called "makefile.opgenc" in the directory of the snippet in order to work out of the box.

Versions Of This Snippet::

Bob Hostern
Snippet ID Download Version Date Posted Author Delete
6950.22012-11-13 02:28Bob Hostern
Changes since last version::
Just to notify you of the format the "makefile.opgenc" file must be in.
###################################
First line: Number of lines in file
Other lines: The lines of code.
If they are not in this format, it will not work. Also, if the first number is too:
High: Throws EOF error
Low: Doesn't print out code completely.
Thanks for reading my babbling.
~~Bobhostern
6930.12012-11-13 02:19Bob Hostern

Download a raw-text version of this code by clicking on "Download Version"

 


Latest Snippet Version: :0.2

class Genlib
	def Genlib.start
		file = File.open("makefile.opgenc", "r")
		reps = file.readline.to_i
		Dir.mkdir("output") unless File.exists?("output")
		adir = Dir.pwd
		Dir.chdir("output")
		output = File.new("output.rb", "w") unless File.exists?("output.rb")
		if output == nil
			output = File.open("output.rb", "w") if File.exists?("output.rb")
		end
		reps.times do 
			output.puts("#{file.readline}")
		end
		Dir.chdir(adir)
	end
end
		

Submit a new version

You can submit a new version of this snippet if you have modified it and you feel it is appropriate to share with others..