From: Holden Glova Date: 2000-12-30T08:04:30+09:00 Subject: [ruby-talk:8309] Re: use of backquotes -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sat, 30 Dec 2000 00:43, I think David Alan Black wrote: > Hello -- > > On Fri, 29 Dec 2000, Holden Glova wrote: > > Hi all, > > > > Can anyone explain why I am getting a nil return value from this? I am > > using backquotes to invoke another Ruby interpreter within the existing > > interpreter against a specific source file. Here is the class that I am > > trying to run from the sub-ruby interpreter. > > > > class Useless > > > > def meth > > puts "Useless method in a useless class" > > end > > > > end > > > > u = Useless.new() > > u.meth() > > > > Here is the output when run at the command line: > > synack@eugene:~/ruby/rubyide$ ruby -w useless.rb > > Useless method in a useless class > > > > Now - when I invoke useless.rb through another class through the use of > > backquotes the result is nil. > > > > class RuntimeInterpreter > > > > def invoke(file) > > `ruby -w #{file} 2>&1`.chomp! > > end > > > > end > > I'm not clear what you mean by result and/or return value. The > runtime output of Useless#meth? and/or the exit status of useless.rb > (as reflect in $?)? I can get at both, so I can't duplicate your > problem if it's one of those: > > r = RuntimeInterpreter.new > s = r.invoke("useless.rb") > p s # => "Useless method in a useless class" > p $? # => 0 > > > David OK David - you are correct it works fine like that (I didn't think it would because it wasn't working within my tests), but when i run it through my tests I still get a nil value. What I mean by the result and/or return value is the runtime output of Useless#meth. Here is the code that I run within RUnit to test this. require 'runit/testcase' require 'runtimeInterpreter' class Test_RuntimeInterpreter < RUNIT::TestCase def testInvoke interpreter = RuntimeInterpreter.new() result = interpreter.invoke("../useless.rb") p result # ---> nil assert(result == "Useless method in a useless class") end end Does this make any sense? I'm confused even more now that David has pointed out that it works fine if I don't run it through my testing suite. - -- Signed, Holden Glova -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.4 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE6TRgEzrxa+Gy/b/4RAuijAJ9C8CTHTAAEQb3MEX5MdKYmR07NqACfU/kM 6I4HyPcdo85d6LU+pyCRbaQ= =f8Im -----END PGP SIGNATURE-----