Sorry that I am asking so trivial, maybe it is too late: can I somehow
mix in module functions into a module or a class? I.e.,
module X
def X.foo; puts "foo"; end
end
module Y
include X # what to write here?
def bar; foo(); end # want to call X.foo
end
Is it even make sense?
In fact, I used ncurses library with ruby 1.6.8, and there I could use
Ncurses methods like in the example above. With the new libs I cannot do
that. Maybe in the old library the Ncurses methods were module AND
instance methods...?
On Mon, 30 Aug 2004 08:29:01 +0900, Ferenc Engard <ferenc@engard.hu> wrote:
In fact, I used ncurses library with ruby 1.6.8, and there I could use
Ncurses methods like in the example above. With the new libs I cannot do
that. Maybe in the old library the Ncurses methods were module AND
instance methods...?
> module X
> def X.foo; puts "foo"; end
> end
>
> module Y
> include X # what to write here?
> def bar; foo(); end # want to call X.foo
> end
>
> Is it even make sense?
You can do it in Ruby, and it makes a lot of sense. Refer to the
pickaxe for details Modules
That description deals with normal mixin functionality, using instance
methods. Here I want to use a module method in another module (or class)
without qualifying it.
At Mon, 30 Aug 2004 09:29:04 +0900,
Ferenc Engard wrote in [ruby-talk:110908]:
> > module X
> > def X.foo; puts "foo"; end
> > end
> >
> > module Y
> > include X # what to write here?
> > def bar; foo(); end # want to call X.foo
> > end
> >
> > Is it even make sense?
>
> You can do it in Ruby, and it makes a lot of sense. Refer to the
> pickaxe for details
> Modules
That description deals with normal mixin functionality, using instance
methods. Here I want to use a module method in another module (or class)
without qualifying it.
X.foo isn't an instance method but a singleton method of X,
that is, it's defined for nothing but X. So you can never call
it without X.