[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

declaration for module methods which need to be implemented

Paul

12/13/2007 10:29:00 PM

Let's say I have the following module:

------------------------
module Parenting

def add_child(a_child)
self.children.push(a_child)
end

def delete_child(a_child)
self.children.delete(a_child)
end

def children
# need to implement
but is there a programtaic way to declare this?
end

end
------------------------

Is there a way to enforce that the 'children' method is understood in
any class which includes this module? Or do I simply rely on a
comment, as above
1 Answer

Trans

12/14/2007 3:28:00 AM

0



On Dec 13, 5:30 pm, Paul <pdavi...@gmail.com> wrote:
> Let's say I have the following module:
>
> ------------------------
> module Parenting
>
> def add_child(a_child)
> self.children.push(a_child)
> end
>
> def delete_child(a_child)
> self.children.delete(a_child)
> end
>
> def children
> # need to implement
> but is there a programtaic way to declare this?
> end
>
> end
> ------------------------
>
> Is there a way to enforce that the 'children' method is understood in
> any class which includes this module? Or do I simply rely on a
> comment, as above

You general just make a comment in the module docs. Ie.

# The including module must define #children.
#
module Parenting
...
end

Under certain conditions you might provide a default, or raise an
error, eg.

module Parenting
def children
raise NoMethodError
end
end

T.