Dne 9.9.2013 12:45, Vladimir Moravec napsal(a):
Dne 9.9.2013 12:21, Arvin Schnell napsal(a):
Hi,
what is the simplest Ruby based client to test SCR code?
I tried something like this:
module X include Yast r = SCR.Execute(path(".target.bash"), "/usr/bin/true") Builtins.y2milestone(r) end
but here path is undefined.
If you include the Yast module, the 'path' method will be added to the instance methods of the module X, which is a different scope from where you expect it in the code example above.
This should work:
module X include Yast
def scr_execute SCR.Execute(path(".target.bash"), '/usr/bin/true') end end
The 'path' method is a shortcut for Yast::Path.new(*args) [1]. If you want to use it in the module scope, you must specify the full namespace.
I was a bit incorrect, sorry. As the 'include' statement puts the constants of the Yast module into the scope of module X, it's not required to use the 'Yast' namespace for accessing the 'Path': module X include Yast r = SCR.execute(Path.new('.target.bash'), '/usr/bin/true') end However, the SCR call will be executed only once during module X evaluation and because you assigned it to a local module variable it is practically useless - typically you would want it for a constant which makes is useful after you mix-in the module X into another class or module where you can make use of it. vlado
[1] https://github.com/yast/yast-ruby-bindings/blob/master/src/ruby/yast/yast.rb
vlado
Regards, Arvin