Class: Shoes::Widget

Inherits:
Object show all
Defined in:
lib/shoes/widget.rb

Class Method Summary collapse

Class Method Details

.inherited(klass, &blk) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/shoes/widget.rb', line 3

def self.inherited klass, &blk
  m = klass.to_s[/(^|::)(\w+)$/, 2].
          gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
          gsub(/([a-z\d])([A-Z])/,'\1_\2').downcase
  Shoes::App.class_eval do
    define_method m do |*args, &blk|
      klass.send :class_variable_set, :@@__app__, self
      parent = cslot
      klass.new(*args, &blk).tap do |s|
        s.define_singleton_method(:parent){parent}
      end
    end
  end
  klass.class_eval do
    define_method :method_missing do |*args, &blk|
      klass.send(:class_variable_get, :@@__app__).send *args, &blk
    end
  end
end