# Question DRb class definition share or not share

**URL:** <https://www.ruby-forum.com/t/question-drb-class-definition-share-or-not-share/116959>\
**Category:** Ruby\
**Created:** [October 11, 2007, 5:47pm UTC](https://www.ruby-forum.com/t/question-drb-class-definition-share-or-not-share/116959 "2007-10-11T17:47:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/cc9497/32.png) [@jack](https://www.ruby-forum.com/u/jack)\
**Post date:** [October 11, 2007, 5:47pm UTC](https://www.ruby-forum.com/t/question-drb-class-definition-share-or-not-share/116959/1 "2007-10-11T17:47:20Z")

</div>

Just go through ruby cookbook & only tutorial for any DRb stuff. But I  
need help explain below example that I don’t understand why DRbUndump  
is not needed. On some of the samples, I see class definition is  
defined in a separate file and was ‘require’ by both client & server.  
But in this case, the class definition is embedded in server side  
code.

The below code works. I would think variable ‘ro’ in client represent  
a proxy. So on the server side, the class definiton probably need to  
include DRbUndump. Can anyone explain to my confusion?

# client

require ‘drb’  
DRb.start\_service  
ro = DRbObject.new(nil, ‘druby://localhost:7777’)  
print ro.songname

#server  
#!/usr/local/bin/ruby  
require ‘drb’

class SongNameServer  
def initialize(str)  
@filename = str  
end  
def songname  
f = File.new(@filename)  
return f.readline  
end  
end

DRb.start\_service(“druby://localhost:7777”, SongNameServer.new("/tmp/  
songname"))  
puts DRb.uri

DRb.thread.join

---

<div class="post-metadata">

**Author:** ![jack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/cc9497/32.png) [@jack](https://www.ruby-forum.com/u/jack)\
**Post date:** [October 11, 2007, 6:11pm UTC](https://www.ruby-forum.com/t/question-drb-class-definition-share-or-not-share/116959/2 "2007-10-11T18:11:25Z")

</div>

On Oct 11, 2007, at 08:45 , Jack wrote:

> Just go through ruby cookbook & only tutorial for any DRb stuff. But I  
> need help explain below example that I don’t understand why DRbUndump  
> is not needed. On some of the samples, I see class definition is  
> defined in a separate file and was ‘require’ by both client & server.  
> But in this case, the class definition is embedded in server side  
> code.
> 
> The below code works. I would think variable ‘ro’ in client represent  
> a proxy. So on the server side, the class definiton probably need to  
> include DRbUndump. Can anyone explain to my confusion?

This is exactly right. DRbUndumped forces the creation of a proxy  
object on the client.

---

<div class="post-metadata">

**Author:** ![jack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/cc9497/32.png) [@jack](https://www.ruby-forum.com/u/jack)\
**Post date:** [October 11, 2007, 7:32pm UTC](https://www.ruby-forum.com/t/question-drb-class-definition-share-or-not-share/116959/3 "2007-10-11T19:32:30Z")

</div>

On Oct 11, 12:10 pm, Eric H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Oct 11, 2007, at 08:45 , Jack wrote:
> 
> > Just go through ruby cookbook & only tutorial for any DRb stuff. But I  
> > need help explain below example that I don’t understand why DRbUndump  
> > is not needed. On some of the samples, I see class definition is  
> > defined in a separate file and was ‘require’ by both client & server.  
> > But in this case, the class definition is embedded in server side  
> > code.

> This is exactly right. DRbUndumped forces the creation of a proxy  
> object on the client.

Thanks Eric, it is much clear to me now! The recipe 16.10 of ruby  
cookbook include class definition on both client and server that was  
not actually required on client side. From other examples, it is clear  
now when I need it. I think I need to watch out the parameters pass to  
the method.

Your online tutorial also very helpful, BTW, thanks again!
