On Wed, 7 Aug 2013 12:01:18 +0200
Arvin Schnell <[email protected]> wrote:

> 
> Hi,
>

Hi Arvin,
 
> I would like to use some classes in the converted ruby code but I
> have problems with function lookup.
> 
> I have figured out how to call functions (e.g. ArrangeButtons
> from include/partitioning/ep-lib.rb in my class method by using
> "module_function :ArrangeButtons" in ep-lib.rb. The problem now
> is that the method deep_copy cannot be found inside
> ArrangeButtons.
> 

OK, I think there is needed some explanations.
At first link to explanation how modules works in ruby
http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html

With this background information it is easy to see where is your
problem. We convert includes to mixins and such mixins depends on
methods in given class, especially on other mixins in Client or
Module [1]. And you want to use Module just like namespace for method,
but such namespace doesn't have given methods.

> It works if I use "include PartitioningEpLibInclude" inside my
> class but I don't like to extend the classes with lots of general
> utility functions.
> 
> So what's the correct way here?

Well, I check such method and you can remove deep copy as ret is newly
generated and buttons is not modified, so you can pass it as reference.
Just note that if you use another method for module you also need to
make it available, but it is not this case.

But for me correct way is to move it outside. So you can create in lib
directory something like storage/ui_ext.rb

Then have there something like:

module Yast
  module UI
    def self.ArrangeButtons buttons
      ...
    end
  end
end

and in your code then
require "storage/ui_ext"

module Yast
  class Foo
     def m
       UI.ArrangeButtons
     end
  end
end

This show nice ruby feature, that allows extend classes. Of course
another solution can be add it directly ui bindings or if you find it
useful, I can add it to ruby bindings, so everyone can use it.

If you have another issue or if something is not clear do not hesitate
to ask. I can also provide more links that explain how ruby works.
 Josef

> 
> Attached is a patch.
> 
> The error message is:
> 
> Client call failed with undefined method `deep_copy' for
> Yast::PartitioningEpLibInclude:Module and backtrace
> ["/usr/share/YaST2/include/partitioning/ep-lib.rb:503:in
> `ArrangeButtons'",
> "/usr/share/YaST2/include/partitioning/ep-all.rb:183:in
> `create'", ...
> 
> ciao Arvin
> 

-- 
To unsubscribe, e-mail: [email protected]
To contact the owner, e-mail: [email protected]

Reply via email to