Declaration for module methods which need to be implemented

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

On Dec 13, 2007 11:30 PM, Paul [email protected] wrote:

Let’s say I have the following module:
[…]
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

There are ways (you can play around with Parenting.inherited and do
method rewrites), yet I suspect you’re better off with a comment. All
methods for ensuring this have limitations that will block some cases
of valid code (though that may be resolved by adding a sort of
say-that-it-is-OK method).

Eivind.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs