Why does drb.rb depend on its filename?

J

Jay Levitt

I was creating my first DRb server, and ran into a trouble with ACLs. I
wanted to put a debug statement into DRb::Accept, so I copied it to my
directory, renamed it jrb.rb, and required it with the new name. But when
I did that, I got an error at launch:

....jrb.rb:1047: undefined method `to_s' for class `DRb::DRbObject'
(NameError)

And the same error happened when I left jrb.rb in /usr/local/lib/ruby/1.8.
So it's not the path - it's the filename.

What's going on? It works fine when run as drb.rb.

Jay Levitt
 
E

Eric Hodel

I was creating my first DRb server, and ran into a trouble with
ACLs. I
wanted to put a debug statement into DRb::Accept, so I copied it to my
directory, renamed it jrb.rb, and required it with the new name.
But when
I did that, I got an error at launch:

....jrb.rb:1047: undefined method `to_s' for class `DRb::DRbObject'
(NameError)

And the same error happened when I left jrb.rb in /usr/local/lib/
ruby/1.8.
So it's not the path - it's the filename.

What's going on? It works fine when run as drb.rb.

It would be easier to tell you with an example.
 
J

Jay Levitt

It would be easier to tell you with an example.

$ cp /usr/local/lib/ruby/1.8/drb/drb.rb jrb.rb
$ cat > test.rb

#!/usr/local/bin/ruby

require "jrb"

def main
DRb.start_service("druby://localhost:8000", IceDrb.new())
DRb.thread.join
end

class IceDrb
def message
puts "message!"
end
end

main
 
E

Eric Hodel

$ cp /usr/local/lib/ruby/1.8/drb/drb.rb jrb.rb
$ cat > test.rb

#!/usr/local/bin/ruby

require "jrb"

drb is more than one file so you need to fix your requires.

$ ruby test.rb
/jrb.rb:1059: undefined method `to_s' for class
`DRb::DRbObject' (NameError)
from test.rb:3
$ cat -n jrb.rb | grep 1059
1059 undef :to_s
$ grep require jrb.rb
require 'socket'
require 'thread'
require 'fcntl'
require 'drb/eq'
[...]
$ grep require /usr/local/lib/ruby/1.8/drb/eq.rb
require 'drb/drb'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top