On Mon, Sep 09, 2013 at 12:21:31PM +0200, Arvin Schnell wrote: > what is the simplest Ruby based client to test SCR code?
$ ruby -r yast -e 'Yast::SCR.Execute(Yast::Path.new(".target.bash"), "xeyes")'
> 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.
Ruby modules, besides being namespaces as you would expect, are
designed to work as *mixins*. That is, a def in a module is by
default available to *instances* of classes that include the module.
Above, "path" is undefined because you call it in the X module, not
in an object.
Many modules are designed to work without instances, but they must
explicitly declare their methods as such with
http://www.ruby-doc.org/docs/ProgrammingRuby/html/ref_c_module.html#Module.module_function
or with "extend self" which is a cryptic way of doing so for all
its methods.
Attached is a working example similar to yours.
--
Martin Vidner, Cloud & Systems Management Team
http://en.opensuse.org/User:Mvidner
Kuracke oddeleni v restauraci je jako fekalni oddeleni v bazenu
require "yast"
class X
include Yast
def f
r = SCR.Execute(path(".target.bash"), "/usr/bin/true")
Builtins.y2milestone("%1", r)
end
end
X.new.f
signature.asc
Description: Digital signature
