views:

40

answers:

1

Hi, I have a sinatra web application and a C++ library that I can 'require' in sinatra (ruby) using bindings created by swig.

I also have a second -very similar- library, in which the function names are partially the same as in the first one. When I require them both, the one that is loaded first 'wins', i.e. calls to the ambiguous function names are always mapped to this library.

The reason is that 'require' does only load stuff that is not already loaded, whereas 'load' reloads no matter what. However, 'load' seems not to be applicable to .so files, only to ruby source files. Any help?

Thank you

A: 

require looks in $" array to determine if a module should be reloaded. You could try deleting it and requiring. Not sure if this will work for your use case, though, as it seems that the namespace still can be left polluted.

irb(main):001:0> require 'mysql'
=> true
irb(main):002:0> require 'mysql'
=> false
irb(main):003:0> $".delete('mysql.so')
=> "mysql.so"
irb(main):004:0> require 'mysql'
/usr/lib64/ruby/site_ruby/1.8/x86_64-linux/mysql.so: warning: already initialized constant MysqlRes
/usr/lib64/ruby/site_ruby/1.8/x86_64-linux/mysql.so: warning: already initialized constant MysqlField
/usr/lib64/ruby/site_ruby/1.8/x86_64-linux/mysql.so: warning: already initialized constant MysqlError
/usr/lib64/ruby/site_ruby/1.8/x86_64-linux/mysql.so: warning: already initialized constant VERSION
/usr/lib64/ruby/site_ruby/1.8/x86_64-linux/mysql.so: warning: already initialized constant OPT_CONNECT_TIMEOUT
/usr/lib64/ruby/site_ruby/1.8/x86_64-linux/mysql.so: warning: already initialized constant OPT_COMPRESS
/usr/lib64/ruby/site_ruby/1.8/x86_64-linux/mysql.so: warning: already initialized constant OPT_NAMED_PIPE
<snip>
=> true 
Mark
Doesn't help in my case: :-( After deleting the entry from $", I still can not reload.irb(main):004:0> require 'libbbrc/bbrc.so'=> false
A.M.
It works here! Will see, whether namespace is polluted. Sorry for the previous comment.
A.M.