/** Create the ObjectSpace module and add it to the Ruby runtime. */ public static RubyModule createObjectSpaceModule(Ruby runtime) { RubyModule objectSpaceModule = runtime.defineModule("ObjectSpace"); runtime.setObjectSpaceModule(objectSpaceModule); objectSpaceModule.defineAnnotatedMethods(RubyObjectSpace.class); return objectSpaceModule; }
public static RubyModule createComparable(Ruby runtime) { RubyModule comparableModule = runtime.defineModule("Comparable"); runtime.setComparable(comparableModule); comparableModule.defineAnnotatedMethods(RubyComparable.class); return comparableModule; }
/** Create the Zlib module and add it to the Ruby runtime. */ public static RubyModule createZlibModule(Ruby runtime) { RubyModule result = runtime.defineModule("Zlib"); RubyClass gzfile = result.defineClassUnder("GzipFile", runtime.getObject(), RubyGzipFile.GZIPFILE_ALLOCATOR); gzfile.defineAnnotatedMethods(RubyGzipFile.class); RubyClass gzreader = result.defineClassUnder("GzipReader", gzfile, RubyGzipReader.GZIPREADER_ALLOCATOR); gzreader.includeModule(runtime.getEnumerable()); gzreader.defineAnnotatedMethods(RubyGzipReader.class); RubyClass standardError = runtime.getStandardError(); RubyClass zlibError = result.defineClassUnder("Error", standardError, standardError.getAllocator()); gzreader.defineClassUnder("Error", zlibError, zlibError.getAllocator()); RubyClass gzwriter = result.defineClassUnder("GzipWriter", gzfile, RubyGzipWriter.GZIPWRITER_ALLOCATOR); gzwriter.defineAnnotatedMethods(RubyGzipWriter.class); result.defineConstant("ZLIB_VERSION", runtime.newString("1.2.1")); result.defineConstant("VERSION", runtime.newString("0.6.0")); result.defineConstant("BINARY", runtime.newFixnum(0)); result.defineConstant("ASCII", runtime.newFixnum(1)); result.defineConstant("UNKNOWN", runtime.newFixnum(2)); result.defineConstant("DEF_MEM_LEVEL", runtime.newFixnum(8)); result.defineConstant("MAX_MEM_LEVEL", runtime.newFixnum(9)); result.defineConstant("OS_UNIX", runtime.newFixnum(3)); result.defineConstant("OS_UNKNOWN", runtime.newFixnum(255)); result.defineConstant("OS_CODE", runtime.newFixnum(11)); result.defineConstant("OS_ZSYSTEM", runtime.newFixnum(8)); result.defineConstant("OS_VMCMS", runtime.newFixnum(4)); result.defineConstant("OS_VMS", runtime.newFixnum(2)); result.defineConstant("OS_RISCOS", runtime.newFixnum(13)); result.defineConstant("OS_MACOS", runtime.newFixnum(7)); result.defineConstant("OS_OS2", runtime.newFixnum(6)); result.defineConstant("OS_AMIGA", runtime.newFixnum(1)); result.defineConstant("OS_QDOS", runtime.newFixnum(12)); result.defineConstant("OS_WIN32", runtime.newFixnum(11)); result.defineConstant("OS_ATARI", runtime.newFixnum(5)); result.defineConstant("OS_MSDOS", runtime.newFixnum(0)); result.defineConstant("OS_CPM", runtime.newFixnum(9)); result.defineConstant("OS_TOPS20", runtime.newFixnum(10)); result.defineConstant("DEFAULT_STRATEGY", runtime.newFixnum(0)); result.defineConstant("FILTERED", runtime.newFixnum(1)); result.defineConstant("HUFFMAN_ONLY", runtime.newFixnum(2)); result.defineConstant("NO_FLUSH", runtime.newFixnum(0)); result.defineConstant("SYNC_FLUSH", runtime.newFixnum(2)); result.defineConstant("FULL_FLUSH", runtime.newFixnum(3)); result.defineConstant("FINISH", runtime.newFixnum(4)); result.defineConstant("NO_COMPRESSION", runtime.newFixnum(0)); result.defineConstant("BEST_SPEED", runtime.newFixnum(1)); result.defineConstant("DEFAULT_COMPRESSION", runtime.newFixnum(-1)); result.defineConstant("BEST_COMPRESSION", runtime.newFixnum(9)); result.defineConstant("MAX_WBITS", runtime.newFixnum(15)); result.defineAnnotatedMethods(RubyZlib.class); result.defineClassUnder("StreamEnd", zlibError, zlibError.getAllocator()); result.defineClassUnder("StreamError", zlibError, zlibError.getAllocator()); result.defineClassUnder("BufError", zlibError, zlibError.getAllocator()); result.defineClassUnder("NeedDict", zlibError, zlibError.getAllocator()); result.defineClassUnder("MemError", zlibError, zlibError.getAllocator()); result.defineClassUnder("VersionError", zlibError, zlibError.getAllocator()); result.defineClassUnder("DataError", zlibError, zlibError.getAllocator()); RubyClass gzError = gzfile.defineClassUnder("Error", zlibError, zlibError.getAllocator()); gzfile.defineClassUnder("CRCError", gzError, gzError.getAllocator()); gzfile.defineClassUnder("NoFooter", gzError, gzError.getAllocator()); gzfile.defineClassUnder("LengthError", gzError, gzError.getAllocator()); // ZStream actually *isn't* allocatable RubyClass zstream = result.defineClassUnder( "ZStream", runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR); zstream.defineAnnotatedMethods(ZStream.class); zstream.undefineMethod("new"); RubyClass infl = result.defineClassUnder("Inflate", zstream, Inflate.INFLATE_ALLOCATOR); infl.defineAnnotatedMethods(Inflate.class); RubyClass defl = result.defineClassUnder("Deflate", zstream, Deflate.DEFLATE_ALLOCATOR); defl.defineAnnotatedMethods(Deflate.class); runtime .getKernel() .callMethod(runtime.getCurrentContext(), "require", runtime.newString("stringio")); return result; }