# Initializing $LOAD\_PATH manually? (embedding ruby)

**URL:** <https://www.ruby-forum.com/t/initializing-load-path-manually-embedding-ruby/65634>\
**Category:** Ruby\
**Created:** [August 20, 2006, 1:19am UTC](https://www.ruby-forum.com/t/initializing-load-path-manually-embedding-ruby/65634 "2006-08-20T01:19:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![agnathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@agnathan](https://www.ruby-forum.com/u/agnathan)\
**Post date:** [August 20, 2006, 1:19am UTC](https://www.ruby-forum.com/t/initializing-load-path-manually-embedding-ruby/65634/1 "2006-08-20T01:19:58Z")

</div>

Hi,

I am embedding ruby in an application and shipping it with app as  
well, so I need to setup the load path manually instead of calling  
ruby\_init\_loadpath(). Here is the code:

```
NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [NSString stringWithFormat:@"%@/../Resources/ruby",

```

[bundle pathForAuxiliaryExecutable:@“My App”]];  
load\_path = rb\_ary\_new();  
rb\_ary\_push(load\_path, rb\_str\_new2([[NSString stringWithFormat:@"%@/%  
s", path, “site\_ruby/1.8”] UTF8String]));  
rb\_ary\_push(load\_path, rb\_str\_new2([[NSString stringWithFormat:@"%@/%  
s", path, “site\_ruby/1.8/powerpc-darwin8.7.0”] UTF8String]));  
rb\_ary\_push(load\_path, rb\_str\_new2([[NSString stringWithFormat:@"%@/%  
s", path, “site\_ruby”] UTF8String]));  
rb\_ary\_push(load\_path, rb\_str\_new2([[NSString stringWithFormat:@"%@/%  
s", path, “1.8”] UTF8String]));  
rb\_ary\_push(load\_path, rb\_str\_new2([[NSString stringWithFormat:@"%@/%  
s", path, “1.8/powerpc-darwin8.7.0”] UTF8String]));  
rb\_gv\_set("$:", load\_path);

I get this error:

```
ruby: $: is a read-only variable (NameError)

```

How can I get around this?

Thanks,  
– Daniel

---

<div class="post-metadata">

**Author:** ![agnathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@agnathan](https://www.ruby-forum.com/u/agnathan)\
**Post date:** [August 20, 2006, 1:42am UTC](https://www.ruby-forum.com/t/initializing-load-path-manually-embedding-ruby/65634/2 "2006-08-20T01:42:00Z")

</div>

On Aug 19, 2006, at 7:18 PM, Daniel H. wrote:

> I get this error:
> 
> ruby: $: is a read-only variable (NameError)
> 
> How can I get around this?

Well, that was dumb of me. This worked:

NSBundle \*bundle = [NSBundle mainBundle];  
NSString \*path = [NSString stringWithFormat:@"%@/…/Resources/ruby",  
[bundle pathForAuxiliaryExecutable:@“My App”]];  
VALUE load\_path = rb\_gv\_get("$:");  
rb\_ary\_push(load\_path, rb\_str\_new2([[NSString stringWithFormat:@"%@/%  
s", path, “site\_ruby/1.8”] UTF8String]));  
rb\_ary\_push(load\_path, rb\_str\_new2([[NSString stringWithFormat:@"%@/%  
s", path, “site\_ruby/1.8/powerpc-darwin8.7.0”] UTF8String]));  
rb\_ary\_push(load\_path, rb\_str\_new2([[NSString stringWithFormat:@"%@/%  
s", path, “site\_ruby”] UTF8String]));  
rb\_ary\_push(load\_path, rb\_str\_new2([[NSString stringWithFormat:@"%@/%  
s", path, “1.8”] UTF8String]));  
rb\_ary\_push(load\_path, rb\_str\_new2([[NSString stringWithFormat:@"%@/%  
s", path, “1.8/powerpc-darwin8.7.0”] UTF8String]));  
//rb\_p(rb\_gv\_get("$:"));

– Daniel

---

<div class="post-metadata">

**Author:** ![agnathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@agnathan](https://www.ruby-forum.com/u/agnathan)\
**Post date:** [August 20, 2006, 4:14am UTC](https://www.ruby-forum.com/t/initializing-load-path-manually-embedding-ruby/65634/3 "2006-08-20T04:14:08Z")

</div>

Hi,

At Sun, 20 Aug 2006 08:40:19 +0900,  
Daniel H. wrote in [ruby-talk:209438]:

> Well, that was dumb of me. This worked:
> 
> NSBundle \*bundle = [NSBundle mainBundle];  
> NSString \*path = [NSString stringWithFormat:@"%@/…/Resources/ruby",  
> [bundle pathForAuxiliaryExecutable:@“My App”]];  
> VALUE load\_path = rb\_gv\_get("$:");  
> rb\_ary\_push(load\_path, rb\_str\_new2([[NSString stringWithFormat:@"%@/%  
> s", path, “site\_ruby/1.8”] UTF8String]));

Or, you can use ruby\_incpush(), which splits path list with  
path separator.
