Hi,

At Fri, 26 May 2006 14:48:55 +0900,
Nobuyoshi Nakada wrote in [ruby-core:07922]:
> By linking following extension library statically, rubygems.rb will be
> loaded even if no -rubygems option is in RUBYOPT nor command line.

This can achieve other hacks. 

E.g., adding vendor_ruby to $LOAD_PATH.

/* ext/vendor/vendor.c */
#include "ruby.h"

extern VALUE rb_load_path;

void
Init_vendor(void)
{
    static const char site[] = "/site_ruby";
    static const char vendor[] = "/vendor_ruby";
    VALUE vendors = 0;
    long i;

    for (i = 0; i < RARRAY(rb_load_path)->len; ++i) {
	VALUE path = RARRAY(rb_load_path)->ptr[i];
	const char *s = strstr(StringValuePtr(path), site), *e;
	long l;

	if (s && (!*(e = s + sizeof(site) - 1) || *e == '/')) {
	    VALUE newpath = rb_str_new(0, RSTRING(path)->len - sizeof(site) + sizeof(vendor));
	    char *p = RSTRING(newpath)->ptr;
	    memcpy(p, RSTRING(path)->ptr, l = p - RSTRING(path)->ptr);
	    memcpy(p += l, vendor, sizeof(vendor) - 1);
	    memcpy(p += sizeof(vendor) - 1, p + sizeof(site) - 1,
		   RSTRING(path)->len - l - sizeof(site));
	    if (!vendors) vendors = rb_ary_new();
	    rb_ary_push(vendors, newpath);
	}
	else if (vendors && RARRAY(vendors)->len > 0) {
	    rb_funcall(rb_load_path, rb_intern("[]="), 3, INT2FIX(i + 1), INT2FIX(0), vendors);
	    i += RARRAY(vendors)->len;
	    rb_ary_clear(vendors);
	}
    }
    if (vendors && RARRAY(vendors)->len > 0) {
	rb_ary_concat(rb_load_path, vendors);
    }
}

-- 
Nobu Nakada