On Mon, Oct 1, 2012 at 6:34 PM, ajay paswan [email protected]
wrote:
start up the DRb service
object[0].each do |aa|
puts “all string reversed”
–
Posted via http://www.ruby-forum.com/.
If you check the DRB docs here
(Index of Classes & Methods in drb: Ruby Standard Library Documentation (Ruby 1.9.2)), you
will see:
“Any type of object can be passed as an argument to a dRuby call or
returned as its return value. By default, such objects are dumped or
marshalled at the local end, then loaded or unmarshalled at the remote
end. The remote end therefore receives a copy of the local object, not
a distributed reference to it; methods invoked upon this copy are
executed entirely in the remote process, not passed on to the local
original. This has semantics similar to pass-by-value.”
What this means is that the methods you call on “remote_array” are
passed to the server, executed in the server, and the result of the
method call is marshalled and sent to the client. The client then
unmarshalls it and has a local copy.
So, you have two objects in your example: remote_array and
remote_array[0], which is another array. When you do remote_array[0],
you are calling method [] on the remote array, this call is executed
in the server. This call returns an array, which is is marshalled and
unmarshalled, resulting in the client having another copy. Anything
that you do over this array is only done locally.
To achieve what you want to do, you have to just call methods on the
remote array. So something like this could work:
1.9.2p290 :041 > remote_array.map! do |el|
1.9.2p290 :042 > if Array === el
1.9.2p290 :043?> el.map{|s| s.reverse}
1.9.2p290 :044?> else
1.9.2p290 :045 > el
1.9.2p290 :046?> end
1.9.2p290 :047?> end
=> [[“tsrif”, “dnoces”, “driht”, “htruof”], false]
1.9.2p290 :048 > remote_array[1] = true
=> true
Which as you see is a bit weird, but this is because the structure you
chose. I know this is just an example, but it shows that you should
model your server objects in such a way to make easy for the clients
to do the stuff.
Jesus.