Hi,
is the Ruby-'include' equal to a C++-'using' statement? Meant for namespace issues. Or does it have a bigger result?
Thanks,
Alex.
Selon Alexander Fleck <Fleck@schleissheimer.de>:
Hi,
is the Ruby-'include' equal to a C++-'using' statement? Meant for namespace
issues. Or does it have a bigger result?
Thanks,
Alex.
"include" is used to mix in a module into a class. It has nothing to do with
namespaces, but is rather a way to quickly add functionality to a class beyond
what is given by its superclass without resorting to multiple inheritance.
Mixins are in a way similar to Java interfaces, except that they contain
fully-fledged methods, rather than just method signatures.
Note that Ruby 1.9 (the development version) now has the "using" keyword for
namespaces too (check out:
http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/6a732d353724f801/de6275a6a51b6bcd#de6275a6a51b6bcd\).
But since Ruby 1.9 is highly experimental, it might change before it becomes the
stable Ruby2.
···
--
Christophe Grandsire.
http://rainbow.conlang.free.fr
It takes a straight mind to create a twisted conlang.
Christophe Grandsire wrote:
Selon Alexander Fleck <Fleck@schleissheimer.de>:
Hi,
is the Ruby-'include' equal to a C++-'using' statement? Meant for
namespace issues. Or does it have a bigger result?
Thanks,
Alex."include" is used to mix in a module into a class. It has nothing to
do with namespaces, but is rather a way to quickly add functionality
to a class beyond what is given by its superclass without resorting
to multiple inheritance=
Adding to that "extend" is more similar to "using". Using "extend" you
can make some things (i.e. methods) from a module directly available.
Kind regards
robert
Selon Robert Klemme <bob.news@gmx.net>:
Adding to that "extend" is more similar to "using". Using "extend" you
can make some things (i.e. methods) from a module directly available.
Indeed. And if you defined module methods in the module, you can even call them
directly with the module name, without having to use "extend" to access them.
In other words, one can, and does, use modules for namespaces already. You just
*don't* do that with "include", but rather without it .
···
--
Christophe Grandsire.
http://rainbow.conlang.free.fr
It takes a straight mind to create a twisted conlang.