lib/culerity/remote_object_proxy.rb in culerity-0.2.6 vs lib/culerity/remote_object_proxy.rb in culerity-0.2.7

- old
+ new

@@ -19,12 +19,12 @@ # def id send_remote(:id) end - def method_missing(name, *args) - send_remote(name, *args) + def method_missing(name, *args, &block) + send_remote(name, *args, &block) end # # Calls the passed method on the remote object with any arguments specified. # Behaves the same as <code>Object#send</code>. @@ -32,13 +32,13 @@ # If you pass it a block then it will append the block as a "lambda { … }". # If your block returns a lambda string ("lambda { … }") then it will be passed # straight through, otherwise it will be wrapped in a lambda string before sending. # def send_remote(name, *args, &blk) - input = [remote_object_id, %Q{"#{name}"}, *args.map{|a| a.inspect}] - input << block_to_string(&blk) if block_given? - @io << "[#{input.join(", ")}]\n" + input = [remote_object_id, %Q{"#{name}"}, *args.map{|a| arg_to_string(a)}] + serialized_block = ", #{block_to_string(&blk)}" if block_given? + @io << "[[#{input.join(", ")}]#{serialized_block}]\n" process_result @io.gets.to_s.strip end def exit @io << '["_exit_"]' @@ -65,9 +65,17 @@ result = block.call.to_s unless result.is_a?(String) && result[/^lambda \s* \{ .*? \}/x] result = "lambda { #{result} }" end result + end + + def arg_to_string(arg) + if arg.is_a?(Proc) + block_to_string(&arg) + else + arg.inspect + end end def remote_object_id @remote_object_id end