On Fri, Aug 09, 2013 at 04:58:22PM +0200, David Majda wrote:
Hi,
Dne 7.8.2013 12:01, Arvin Schnell napsal(a):>
Hi,
I would like to use some classes in the converted ruby code but I have problems with function lookup.
[...]
So what's the correct way here?
I didn't examine your patch in detail, but it seems to me that you are mixing Ruby concepts (classes, modules) with ones inherited from YaST (mainly includes). My general recommendations are the following:
- If you create a new class, put it into a separate file, don't make it inherit from anything in Yast:: and don't make it part of any YaST client, module or include. That will ensure separation of concepts. One class per file is also usual convention in Ruby world.
Where should the new file be placed and how do I "include" it? Remember, I'm new to Ruby.
- If you need to use a YaST module in your class, then just import it and use it -- that should work well.
With Yast.import, right?
If you need to use a YaST include in the class, include it via Ruby include as a Ruby module and call its initialize_* method (if any) manually in the constructor.
You correctly note that this is ugly. The better way is probably to extract the include functionality you need into a separate Ruby class/module, use it in your class, and just delegate to the extracted part in the include.
That sound like it involves moving lots of code, more or less all ep-*.rb files. And even then all calls to the extracted functions must be changed to include a namespace, e.g. from doit() to Foo.doit(). Since all mistakes only show up at runtime that's hopeless.
- If you need to use any part of Ruby bindings (e.g. UI shortcuts) in your class, just include the appropriate module. This may lead to some duplication if you do it in many classes, which we will probably need to address soon (in order to prevent everybody doing his own thing).
I would do so in a dozen of classes. Thanks for the help, but I think for the near future I have to put my ideas on ice. ciao Arvin -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org