Class: Class

Inherits:
Object show all
Defined in:
lib/ruby_ext/prototype_inheritance.rb,
lib/ruby_ext/prototype_inheritance.rb

Overview

Inheritance logic

Instance Method Summary collapse

Instance Method Details

#class_prototypeObject



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/ruby_ext/prototype_inheritance.rb', line 51

def class_prototype
  unless @class_prototype
    unless const_defined? :ClassPrototype
      class_eval "module ClassPrototype; end", __FILE__, __LINE__        
    end      
    @class_prototype = const_get :ClassPrototype
    
    (class << self; self end).fixed_include @class_prototype
  end
  @class_prototype
end

#define_class_methods(&block) ⇒ Object



74
75
76
77
# File 'lib/ruby_ext/prototype_inheritance.rb', line 74

def define_class_methods &block
  self.class_prototype.class_eval &block
  # self.extend self.class.prototype
end

#define_instance_methods(&block) ⇒ Object



69
70
71
72
# File 'lib/ruby_ext/prototype_inheritance.rb', line 69

def define_instance_methods &block
  prototype.class_eval &block    
  # self.include prototype
end

#inherit(*classes) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/ruby_ext/prototype_inheritance.rb', line 79

def inherit *classes
  classes.each do |klass|
    raise "You can inherit classes only ('#{klass}')!" unless klass.class == Class
    
    prototype.fixed_include klass.prototype
    # self.include prototype
    
    class_prototype.fixed_include klass.class_prototype
    # (class << self; self end).include class_prototype
    
    # callback
    klass.inherited self if klass.respond_to? :inherited
  end
end

#prototypeObject



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ruby_ext/prototype_inheritance.rb', line 39

def prototype
  unless @prototype
    unless const_defined? :Prototype
      class_eval "module Prototype; end", __FILE__, __LINE__        
    end      
    @prototype = const_get :Prototype
    
    fixed_include @prototype
  end
  @prototype
end