Class: Class

Inherits:
Object
  • Object
show all
Defined in:
lib/abstraction.rb

Instance Method Summary collapse

Instance Method Details

#abstractObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/abstraction.rb', line 4

def abstract
  @abstraction_abstract_class = true

  self.extend Module.new {
    def new(*args, &block)
      if @abstraction_abstract_class
        raise AbstractClassError, "#{self} is an abstract class and cannot be instantiated"
      else
        super *args, &block
      end
    end

    def allocate(*args, &block)
      if @abstraction_abstract_class
        raise AbstractClassError, "#{self} is an abstract class and cannot be instantiated"
      else
        super *args, &block
      end
    end
  }

  nil
end