Hi
I was defining a hierachical error type today and realized
that I had inheritied from a class before it was closed.
It seems to work nicely, but was just wondering why.
Below is an example:
  module A
  
    class MyClassError < StandardError
      class NoBlockError < MyClassError; end
      class IOError      < MyClassError; end
      ...
    end#class MyClassError
    
    class MyClass
      ...
      raise MyClassError::NoBlockError
      ...
      raise MyClassError::IOError
      ...
    end#class MyClass
    
  end#module A
  
I like the way this turned out. Does anyone see a problem with doing this?
···
--
Jim Freeze
 
             
            
              
              
              
            
            
           
          
            
            
              jim@freeze.org wrote:
Hi
I was defining a hierachical error type today and realized
that I had inheritied from a class before it was closed.
It seems to work nicely, but was just wondering why.
Below is an example:
  module A
      class MyClassError < StandardError
      class NoBlockError < MyClassError; end
      class IOError      < MyClassError; end
      ...
    end#class MyClassError
    
      ...
      raise MyClassError::NoBlockError
      ...
      raise MyClassError::IOError
      ...
    end#class MyClass
      end#module A
  I like the way this turned out. Does anyone see a problem with doing this?
My guess: Closing a class isn't really significant, since it can be reopened at any time. The class has been fully defined when the "class XXX < ..." line has been executed. For consistency, the following would have to be equivalent:
   class A
     do_something_with_A
   end
and
   class A
   end # close the class
   class A
     do_something_with_A
   end