"Sean O'Dell" <sean / celsoft.com> wrote in message news:<200406072036.21285.sean / celsoft.com>...
> On Monday 07 June 2004 20:13, Hal Fulton wrote:
> > Semantics, James Thurber notwithstanding, is not a town in Ohio.
> >
> > I think when Rich says "semantics" he means something that can't
> > really be checked by a machine -- the "purpose or function," as it
> > were.
> >
> > I do sometimes wish there were a way to detect semantics -- but the
> > best we could do is simply remove the problem a step further.
> 
> Here's what I'm working on right now for my own purposes.  I've already 
> applied for a RubyForge project so if others find this useful, they can use 
> it too.  Take a look:
> 
> # first class defines the interface
> class MyClass
>   def method1(a, b, c)
>   end
> 
>   def method2(a, b, c = nil)
>   end
> 
>   define_interface(:my_interface, :method1, :method2)
> end
> 
> # of course it has its own interface
> a = MyClass.new
> a.has_interface?(:my_interface) => true
> 
> # second class simply declares that it implements the interface
> class UnrelatedClass
>   declare_interface(:my_interface)
> 
>   def method1(a, b, c)
>   end
> 
>   def method2(a, b, c = nil)
>   end
> end
> 
> # it also implements the interface
> a = UnrelatedClass.new
> a.has_interface?(:my_interface) => true
> 
> # the third class declares the interface
> # but changes one of the methods' parameters to have no default
> class NoncompliantClass
>   declare_interface(:my_interface)
> 
>   def method1(a, b, c)
>   end
> 
>   def method2(a, b, c)
>   end
> end
> 
> # because of the method change, it does not implement the interface
> a = NoncompliantClass.new
> a.has_interface?(:my_interface) => false
> 
> 
> 
> I'm writing a little lib in C to do this right now.  I'm mostly done.  I am 
> fighting with the Ruby C API's class variable access, otherwise I'd be 
> finished.
> 
> 	Sean O'Dell

I published an "interface" module a short while back.  You can find it
on the RAA or at:

http://ruby-miscutils.sourceforge.net

Regards,

dan