From 52e039ac30fec4c7aac8cec64f931145a8e390a7 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 20 Apr 2013 19:33:49 +0200 Subject: some ruby spikes --- toys/brhute-rb/spike/drbssh_test.rb | 68 +++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 toys/brhute-rb/spike/drbssh_test.rb (limited to 'toys/brhute-rb/spike/drbssh_test.rb') diff --git a/toys/brhute-rb/spike/drbssh_test.rb b/toys/brhute-rb/spike/drbssh_test.rb new file mode 100644 index 0000000..8a1f2c2 --- /dev/null +++ b/toys/brhute-rb/spike/drbssh_test.rb @@ -0,0 +1,68 @@ +$:.unshift File.dirname(__FILE__) + +require 'drbssh' # local version of drbssh sudo gem install drbssh + +class Ohmy + def toto + puts 'i am '+`hostname` + return 'i am '+`hostname` + end +end + +# Connect - OK +DRb.start_service 'drbssh://' +remote = DRbObject.new_with_uri("drbssh://_sd/ruby") + +# Simple eval - OK +puts remote.eval('`hostname`') +puts remote.eval('1+1') + +# Send classobj - FAIL +#o = DRbObject.new_with_uri "drbssh://_sd/ruby", Ohmy.new +#Ohmy.new +#o = remote.eval("Ohmy.new") +#class << remote +# undef :instance_eval +# def bla +# puts 'i am '+`hostname` +# end +#end +#remote.bla + +# Create objects - OK +#l = Hash +#l2 = DRbObject.new(l, "drbssh://_sd/ruby") +#remote_hash = remote.eval("@a = {}.extend(DRb::DRbUndumped)") +#puts l2 +#remote_hash = remote.eval("@a = {}.extend(DRb::DRbUndumped)") + +# Send object - OK +l = [1,2,3] +obj = remote.eval("@data = \""+Marshal.dump(l)+"\"") +obj = remote.eval("@a = Marshal.load(@data)") +obj = remote.eval("@a += [4]") +obj += [5] +puts obj + +# Send class object - FAIL +#o = Ohmy.new +#eval("puts o.toto") +#eval("puts Ohmy.new.toto") +#eval("@c = \"Marshal.dump(Ohmy)\"; @d=Marshal.load(eval(@c))") +#eval("@d.new.toto") +#obj = remote.eval("@c = \""+Marshal.dump(Ohmy)+"\"") +#puts obj +#obj = remote.eval("@c.class") +#puts obj +#obj = remote.eval("@c.size") +#puts obj +#obj = remote.eval("@cc = Marshal.load(eval(@c))") +#puts obj +#obj = remote.eval("@o = @cc.new.toto") +#puts obj +#obj = remote.eval("@obj = @o.toto") +#puts obj +#obj = remote.eval("@obj = \""+Marshal.dump(o)+"\"") +#puts obj +#obj = remote.eval("puts Ohmy.new.toto") +#puts obj -- cgit v1.2.3-59-g8ed1b