On Mon, Mar 13, 2006 at 09:16:30AM +0900, ara.t.howard / noaa.gov wrote:
> On Mon, 13 Mar 2006, Yukihiro Matsumoto wrote:
> >The abstract "each" method defined in Enumerable overrides the "each"
> >in the Base class.  I'm not against the idea of abstract (or deferred)
> >method, but sometimes it's not that simple.
> 
> how about something very simple?  i use this in my own code
> 
>   class Module
>     def abstract_method m
>       define_method(m){|*a| raise NotImplementedError}
>     end
>   end
> 
>   module Interface
>     abstract_method "foo"
>     abstract_method "bar"
>   end
> 
>   class C
>     include Interface
>   end

It fails in the very way matz indicated.

class Module
  def abstract_method m
    define_method(m){|*a| raise NotImplementedError}
  end
end

module Interface
  abstract_method :foo
  def bar; foo end
end

class C
  def foo; "C#foo" end
end

class D < C
  include Interface
end

D.new.bar
# ~> -:3:in `foo': NotImplementedError (NotImplementedError)
# ~> 	from -:9:in `bar'
# ~> 	from -:20

-- 
Mauricio Fernandez  -   http://eigenclass.org   -  singular Ruby