From: Rolando Abarca Date: 2008-12-19T04:34:22+09:00 Subject: [ruby-core:20665] best way to handle $: when embedding ruby Hi all, I'm trying to embed ruby in an iPhone App, and so, I have to follow apple rules: I can't just install it in /usr, it has to live inside my app bundle (the app home). I have successfully included ruby, libruby- static.a and a simple script works just fine. I'm concerned on how the $: global variable will be filled though, because AFAIK it is created with compile-time static strings that will not reflect the real directories in my app. So far, this is what I'm doing: void init_ruby_stuff() { ruby_init(); NSString *rubydir = [[NSBundle mainBundle] pathForResource:@"lib" ofType:nil inDirectory:@"ruby"]; // clean $: VALUE libdirs = rb_gv_get("$:"); rb_funcall(libdirs, rb_intern("clear"), 0); // set $: to the lib structure inside $APP/ruby rb_funcall(libdirs, rb_intern("push"), 1, rb_str_new2([[NSString stringWithFormat:@"%@/ruby/1.8", rubydir] cStringUsingEncoding:NSUTF8StringEncoding])); rb_funcall(libdirs, rb_intern("push"), 1, rb_str_new2([[NSString stringWithFormat:@"%@/ruby/site_ruby/1.8/arm-darwin9", rubydir] cStringUsingEncoding:NSUTF8StringEncoding])); rb_funcall(libdirs, rb_intern("push"), 1, rb_str_new2([[NSString stringWithFormat:@"%@/ruby/vendor_ruby/1.8/arm-darwin9", rubydir] cStringUsingEncoding:NSUTF8StringEncoding])); ruby_init_loadpath(); ruby_script("embedded"); } Basically: clearing the content of $: and then pushing some directories, so far so good, but I'm not feeling ok modifying the content of $: in this way... How should I recreate the directory structure? I can't just set it to a fix location, since the application base directory is placed in a sandbox (when developing), with a different prefix each time. NOTE: the ruby directory is a stripped down version of what lies after a make install. The prefix (when configuring) was set to a "ruby" directory inside my app project, that's the reason of the line in the code above to look for the directory "lib" inside "ruby". -- Rolando Abarca M.