Embed arbitrary data and multiple, distinct documents within ruby files.
Find a file
2016-01-06 14:36:04 -08:00
.hgbugs Bug metadata has been initialized. 2011-01-22 01:20:16 -08:00
lib Directory structure reorganization. 2016-01-06 14:36:04 -08:00
spec Directory structure reorganization. 2016-01-06 14:36:04 -08:00
.hgignore Update copyright, make description shorter so it'll look nicer when 2011-01-22 01:54:06 -08:00
.hgsigs Added signature for changeset 62a5ac525ce8 2011-01-22 01:55:55 -08:00
.rspec Directory structure reorganization. 2016-01-06 14:36:04 -08:00
LICENSE Directory structure reorganization. 2016-01-06 14:36:04 -08:00
Rakefile Directory structure reorganization. 2016-01-06 14:36:04 -08:00
README Directory structure reorganization. 2016-01-06 14:36:04 -08:00

Preface:

	Ruby provides an automatic constant called DATA, which is an IO object
	that references all text in the current file under an __END__ token.

	I find it convenient to use the __END__ area to store all sorts of
	stuff, rather than have to worry about distributing separate files.


The problem:

	The DATA constant is determined from whatever ruby believes $0 to be.
	It doesn't work inside of other required libraries, so you'll see stuff
	like this all the time:

	END = File.open( __FILE__ ).read.split( /^__END__/, 2 ).last

	It works, but it's more work than I want to do.


A workaround:

	Chunker solves this by parsing __END__ tokens for you, and making it
	available in the form of a 'DATA_END' constant.  It installs this
	constant into the class that includes Chunker, so you can use it again
	and again, assuming you use a different file for each class.

	It also automatically parses out other things that look like tokens, so
	you can easily have multiple, distinct documents all embedded into the
	__END__ block.


Usage:

	There is no direct interface to Chunker.  Just include it from a
	class to have that file's __END__ data blocks magically become DATA_*
	IO constants within that class.


Example:

	This produces the string "Yep.\n".


		require 'chunker'
		class Foom
			include Chunker
		end

		puts Foom.new.class.const_get( :DATA_WICKED ).read

		__END__
		Stuff in the END block!
		__WOW__
		Ultimate success!
		__WICKED__
		Yep.