# RUBYLIB and shared libraries

**URL:** <https://www.ruby-forum.com/t/rubylib-and-shared-libraries/182772>\
**Category:** Ruby\
**Created:** [February 2, 2010, 5:16pm UTC](https://www.ruby-forum.com/t/rubylib-and-shared-libraries/182772 "2010-02-02T17:16:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [February 2, 2010, 5:16pm UTC](https://www.ruby-forum.com/t/rubylib-and-shared-libraries/182772/1 "2010-02-02T17:16:53Z")

</div>

Hi everyone,

I’m setting up my RUBYLIB variables for use with custom libraries I’ve  
created. I have the following working properly:

C:/lib/wxruby/lib [this points to the custom library path I have set]

Everything is verified with ruby -e “puts $:” …

The first module I created is a module called public\_instance\_methods.rb

Location: C:/lib/wxruby/lib/public\_instance\_methods.rb

module PublicInstanceMethods

# This method sets the default icon for the given window or frame

def set\_icon\_file(file)  
icon\_file = File.join(File.dirname( **FILE** ),"…",“icons”,file)  
set\_icon Wx::Icon.new(icon\_file, Wx::BITMAP\_TYPE\_ICO)  
end

end

My default working project directory is:

E:\project\lib  
“” \core  
“” \icons  
“” \images

In E:\project\lib\core\main.rb I have…

require ‘public\_instance\_methods’  
include PublicInstanceMethods

class GuiMain \< XrcFrameMain  
def initialize  
super()

```
set_icon_file("test.ico")

```

end  
end

Which results into an error saying:

Icon file does not exist:  
C:/lib/wxruby/lib/…/icons/kirin.ico (ArgumentError)

… which means that it’s looking in the lib directory of the included  
module and not the working directory of the application. How should I  
set this method up so that it includes the right path to the ico file?

---

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [February 2, 2010, 5:22pm UTC](https://www.ruby-forum.com/t/rubylib-and-shared-libraries/182772/2 "2010-02-02T17:22:00Z")

</div>

You can use RAILS\_ROOT but I’m sure there is a better way.

---

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [February 2, 2010, 5:42pm UTC](https://www.ruby-forum.com/t/rubylib-and-shared-libraries/182772/3 "2010-02-02T17:42:34Z")

</div>

Jason P. wrote:

> You can use RAILS\_ROOT but I’m sure there is a better way.

wha??

This isn’t a rails discussion topic and has nothing to do with rails.  
Someone else?

---

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [February 2, 2010, 6:38pm UTC](https://www.ruby-forum.com/t/rubylib-and-shared-libraries/182772/4 "2010-02-02T18:38:23Z")

</div>

Sorry, man.

If you want to define the root of your application you could always set  
a  
global variable in your main.rb or set a global variable. Whenever you  
call  
use **FILE** it is the relative path to the file that is calling it so  
in  
your case the shared library file.

---

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [February 2, 2010, 7:18pm UTC](https://www.ruby-forum.com/t/rubylib-and-shared-libraries/182772/5 "2010-02-02T19:18:32Z")

</div>

Jason P. wrote:

> Sorry, man.
> 
> If you want to define the root of your application you could always set  
> a  
> global variable in your main.rb or set a global variable.

Thanks Jason. That’s what I needed:

main.rb

$file\_path = **FILE**

set\_icon\_file($file\_path,"…",“icons”,“test.ico”)

… then in my custom lib directory for PublicInstanceMethods I have:

# This method sets the default icon for the given window or frame

def set\_icon\_file(path, \*file)  
icon\_file = File.join(File.dirname(path), file)  
set\_icon Wx::Icon.new(icon\_file, Wx::BITMAP\_TYPE\_ICO)  
end

… and now everything works fine. If there is a better way of doing  
this with regard to use of custom lib files, please let me know.

Thanks.
