public
Description: Unit tests I wrote way back when I started learning Ruby.
Homepage: http://clarkware.com/cgi/blosxom/2005/03/18
Clone URL: git://github.com/clarkware/ruby-learning-tests.git
ruby-learning-tests / metaprog.rb
100644 34 lines (23 sloc) 0.444 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
module Mixin
  
  def self.included(base)
   base.extend(ClassMethods)
   base.send :include, InstanceMethods
  end
  
  module ClassMethods
    attr_accessor :class_variable
 
    def class_var(s)
      self.class_variable = s
    end
  end
  
  module InstanceMethods
    def instance_method
      puts self.class.class_variable
    end
  end
  
end
 
class Mike
  
  include Mixin
    
  class_var "bar"
  
end
 
m = Mike.new
m.instance_method