1 require 'druby3'
 2 
 3 class Bar
 4     attr_reader :i
 5     def initialize(i)
 6         @i = i
 7     end
 8 end
 9 
10 class Foo < Bar
11     # Initialize @i to 0
12     def initialize(druby)
13         super(0)
14         @druby = druby
15     end
16 
17     # Set @i
18     def foo(i)
19         @i = i
20     end
21 
22     # Return a reference to a new Bar object with Bar.i = @i + 1
23     def bar()
24         b = Bar.new(@i + 1)
25         obj = @druby.create_reference(b)
26         return obj
27     end
28 
29     # Test iteration
30     def each()
31         yield 1
32         yield 2
33         yield 3
34     end
35 
36     # Test exception
37     def throw_exception()
38         raise RuntimeError
39     end
40 end
41 
42 server = DRuby::Server.new('localhost', '4242')
43 f = Foo.new(server)
44 server.bind(f, "foo")
45 server.thread.join