On Tue, 20 Aug 2013 11:50:05 +0200
Arvin Schnell <[email protected]> wrote:

> On Tue, Aug 20, 2013 at 11:15:12AM +0200, Josef Reidinger wrote:
> 
> > Arvin Schnell <[email protected]> wrote:
> 
> > > 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.
> 
> > 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
> 
> But this requires moving more or less all files and functions of
> the expert partitioner around as I already replied to
> Martin. It's simply not worth the effort (and new bugs) -
> remember that all I want is to use existing functions from class
> functions without polluting the classes through mixin.
> 
> Regards,
>   Arvin
> 

You can make a small step instead :)

you can keep ArrangeButtons also in partitioner and just have inside

def ArrangeButtons(buttons)
  UI::ArrangeButtons(buttons)
end

then you are backward compatible, so all your ep stuff works and you
just move one method that I think belongs to different place. This is
how easy is to have backward compatible code in ruby.
Josef
-- 
To unsubscribe, e-mail: [email protected]
To contact the owner, e-mail: [email protected]

Reply via email to