[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-talk
Subject:    Re: Interfaces in Ruby
From:       Paul Brannan <pbrannan () atdesk ! com>
Date:       2003-01-02 16:06:37
[Download RAW message or body]

On Thu, Jan 02, 2003 at 11:49:55PM +0900, Robert wrote:
> since ruby is dynamically type in principle there is no technical need for
> interfaces.  however, if i want to define an interface - say for reasons of
> documentation - what is the suggested way to do so?  create a class with a
> set of methods returning 'nil' or 'self'?  or create a method, that checks
> the interface of an instance and raises a TypeError if any of the methods is
> missing?  what would you suggest?

Make sure whatever mechanism you use is a module and not a class.  Ruby
only has single inheritance, so if it's a class, then I can't get both 
your interface and inherit from another class.

See some discussion on this at (at the bottom under Abstract Base
Classes):

  http://www.rubygarden.org/ruby?RubyFromCpp

See also an earlier thread on this list starting at [ruby-talk:53297].

Paul


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic