"John Kaurin" <jkaurin / home.com>
a ˝─rit le 05/26/01 05:16:06 que :


[...]

> 
> file1.rb
> 
> class A
>   def methodA
>     p "Method A"
>     methodB
>   end
> end
> 
> ---
> 
> file2.rb
> 
> include "file1"
> 
> class B < A
>   def methodB
>     p "Method B"
>   end
> end
> 
> o = B.new
> o.methodA
> 

Hi,
The danger is to call methodA directly for an instance of class A.

What you want to do is more like a "Virtual class" for A (a class
which cannot be instanciate).

The ruby-way to make this kind of thing is module

# file1.rb :
module A
        def methodA
                p "Method A"
                methodB
        end
end

# file2.rb :
require "file1"
class B
        include A
        def methodB
                p "MethodB"
        end
end

o = B.new
o.methodA

Here, an other way (depends on contraints modeling you have) :

class A
        def methodB
                p "Default Method B"
        end
        def methodA
                p "Method A"
                methodB
        end
end
        
class B < A
        def methodB
                p "Method B"
        end
end

In that case, A could be instanciate.

The module solution is better :
 - A is not a real class
 - subclasses of A must define B method

HTH

-- 
GR <guillaume.rumeau / wanadoo.fr>

L'homme est doud'une vaste intelligence 
qui regarde devant elle et au-del(J.L)