Silly question

Hi all,

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...?

Thanks,
Ferenc

Hi all,

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?

You can do it in Ruby, and it makes a lot of sense. Refer to the
pickaxe for details
http://phrogz.net/ProgrammingRuby/tut_modules.html#mixins

···

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...?

Thanks,
Ferenc

Hi,

At Mon, 30 Aug 2004 08:29:01 +0900,
Ferenc Engard wrote in [ruby-talk:110906]:

module X
def X.foo; puts "foo"; end

  def foo;X.foo;end

···

end

--
Nobu Nakada

For more info see Ruby-Talk:109274.

···

On Sunday 29 August 2004 07:29 pm, Ferenc Engard wrote:

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.,

--
T.

> 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.

Ferenc

Hi,

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.

···

--
Nobu Nakada