From: "Jesús Gabriel y Galán" Date: 2012-10-02T02:33:31+09:00 Subject: Re: cannot reverse string using drb :( On Mon, Oct 1, 2012 at 7:24 PM, ajay paswan wrote: > "Jesús Gabriel y Galán" wrote in post > #1078201: >> On Mon, Oct 1, 2012 at 6:34 PM, ajay paswan >> 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 >> (http://ruby-doc.org/stdlib-1.9.2/libdoc/drb/rdoc/index.html), you >> will see: > where is it written, sorry to be stupid, but may be am asking these > questions as I am not comfortable or cannot read doc's any help > please..? Sorry, I pasted the first link, you have to click on the DRb module: http://ruby-doc.org/stdlib-1.9.2/libdoc/drb/rdoc/DRb.html >> >> >> >> 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 > Its great to have so explained answer, but really I am unable to get the > meaniing of codes, and what if I deal with a class's object? >> 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. > Sorry, but can I get an example Sir? What I posted above is an example of the client code that goes with your server. client.rb #!/usr/bin/env ruby -w # simple_client.rb # A simple DRb client require 'drb' DRb.start_service # attach to the DRb server via a URI given on the command line remote_array = DRbObject.new nil, ARGV.shift remote_array.map! do |el| if Array === el el.map{|s| s.reverse} else el end end puts "all string reversed" remote_array[1]=true puts "flag made true to finish" > Its great to have so explained answer, but really I am unable to get the > meaniing of codes, and what if I deal with a class's object? Well, in order to understand DRb you have to know that when you call a method on a remote object it's executed on the server. The result is passed to the client. If you call methods on this result, they are not passed anymore to the server: remote_array = DRbObject.new nil, ARGV.shift first_element = remote_array[0] # the method [] with argument 0 is executed on the server. The result is an Array, which is marshalled and sent to the client. first_element is a *copy* of the server's array. first_element[0] = "test" # now, this method []= with arguments 0 and "test" is executed only on the client, cause it's done against a regular array, and not a DRbObject. Jesus.