druby/attr_reader problem 
Author Message
 druby/attr_reader problem

  I have DRb server that manages marshalized objects in DB. I've
  stored objects of the class below:

  class MyObject
    def initialize( name )

    end
  end

  Then I've fetched them back and all worked fine.


  became:
  class MyObject
    attr_reader :name
    def initialize( name )

    end
  end

  When I've fetched my object from DRb server and called obj.name I
  saw error message:
  undefined method `name' for #<MyClass:0x80e5864>

  p obj
  produced:

  Then I've decided to modify MyClass in such way:
  class MyObject
    def initialize( name )

    end

    def name

    end
  end

  and in this case all works fine. obj.name returns 'test'
  I don't understand why attr_reader doesn't work in my example?

--
Best regards,



Wed, 04 May 2005 20:00:26 GMT  
 druby/attr_reader problem

Hello,

Quote:

>   became:
>   class MyObject
>     attr_reader :name
>     def initialize( name )

>     end
>   end

>   When I've fetched my object from DRb server and called obj.name I
>   saw error message:
>   undefined method `name' for #<MyClass:0x80e5864>

Did you define attr_reader as each of a server and a client?
Which of a server and a client is that an error comes out?

#-- myobject.rb
class MyObject
  attr_reader :name
  def initialize( name )

  end
end

#-- store.rb (server)
require 'drb/drb'
require 'myobject'

class MockDB
  def initialize

  end

  def [](key)
    puts "fetch #{key.inspect}"

  end

  def []=(key, value)
    puts "store #{key.inspect}, #{value.inspect}"

  end
end

DRb.start_service('druby://localhost:12345', MockDB.new)
DRb.thread.join

#-- client.rb
require 'drb/drb'
require 'myobject'

DRb.start_service

db = DRbObject.new(nil, 'druby://localhost:12345')

foo = MyObject.new('foo')
db[foo.name] = foo

bar = MyObject.new('bar')
db[bar.name] = bar

puts db['foo'].name
puts db['bar'].name



Wed, 04 May 2005 20:30:09 GMT  
 druby/attr_reader problem

mmbnj> Hello,

Quote:

>>   became:
>>   class MyObject
>>     attr_reader :name
>>     def initialize( name )

>>     end
>>   end

>>   When I've fetched my object from DRb server and called obj.name I
>>   saw error message:
>>   undefined method `name' for #<MyClass:0x80e5864>

mmbnj> Did you define attr_reader as each of a server and a client?
I can't require my object (class) declarations on the serverside, all
objects are stored in relational DB and server allows to store objects
of any class. So server requires only drb/drb.
mmbnj> Which of a server and a client is that an error comes out?
Error comes out on the clientside, when object is unmarshalized and
received by client. It exists, but doesn't respond to :name. But as I
told before it responds to :name if I define method 'name' to access
instance variable (not reader). This seems strange to me.

--
Best regards,



Fri, 06 May 2005 19:59:09 GMT  
 druby/attr_reader problem

Hi,

Quote:

> >>   became:
> >>   class MyObject
> >>     attr_reader :name
> >>     def initialize( name )

> >>     end
> >>   end

> >>   When I've fetched my object from DRb server and called obj.name I
> >>   saw error message:
> >>   undefined method `name' for #<MyClass:0x80e5864>

                                     =======
                                     MyClass ? MyObject ??

Quote:
> Error comes out on the clientside, when object is unmarshalized and
> received by client. It exists, but doesn't respond to :name. But as I
> told before it responds to :name if I define method 'name' to access
> instance variable (not reader). This seems strange to me.

Hmm, I have no idea. The marshalized data was broken ??
Can I see the simple code which displays the error message?


Fri, 06 May 2005 21:09:30 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Problem with Borges,Apache and dRuby

2. Problem with druby related to TCPServer implementation on linux

3. dRuby problem with Threads

4. attr_reader :foo?

5. attr_reader/writer vs. attr_accessor w/ access control

6. attr_reader, etc.

7. attr_reader for great number of instance vars

8. attr_accessor, attr_reader question

9. Ruby code for attr, attr_accessor, attr_reader, attr_writer ?

10. p24 of Programming Ruby, attr_reader

11. help attr_reader

12. druby vs CORBA vs java-RMI

 

 
Powered by phpBB® Forum Software