removing log dir from .gitignore
[monkeycharger.git] / vendor / rails / activesupport / lib / active_support / vendor / builder / blankslate.rb
blob57701d87137f37d6a89717c9f38e388e44d6b2f4
1 #!/usr/bin/env ruby
2 #--
3 # Copyright 2004 by Jim Weirich (jim@weirichhouse.org).
4 # All rights reserved.
6 # Permission is granted for use, copying, modification, distribution,
7 # and distribution of modified versions of this work as long as the
8 # above copyright notice is included.
9 #++
11 module Builder #:nodoc:
13   # BlankSlate provides an abstract base class with no predefined
14   # methods (except for <tt>\_\_send__</tt> and <tt>\_\_id__</tt>).
15   # BlankSlate is useful as a base class when writing classes that
16   # depend upon <tt>method_missing</tt> (e.g. dynamic proxies).
17   class BlankSlate
18     class << self
20       # Hide the method named +name+ in the BlankSlate class.  Don't
21       # hide +instance_eval+ or any method beginning with "__".
22       def hide(name)
23         undef_method name if
24           instance_methods.include?(name.to_s) and
25           name !~ /^(__|instance_eval)/
26       end
27     end
29     instance_methods.each { |m| hide(m) }
30   end
31 end
33 # Since Ruby is very dynamic, methods added to the ancestors of
34 # BlankSlate <em>after BlankSlate is defined</em> will show up in the
35 # list of available BlankSlate methods.  We handle this by defining a
36 # hook in the Object and Kernel classes that will hide any defined
37 module Kernel #:nodoc:
38   class << self
39     alias_method :blank_slate_method_added, :method_added
41     # Detect method additions to Kernel and remove them in the
42     # BlankSlate class.
43     def method_added(name)
44       blank_slate_method_added(name)
45       return if self != Kernel
46       Builder::BlankSlate.hide(name)
47     end
48   end
49 end
51 class Object
52   class << self
53     alias_method :blank_slate_method_added, :method_added
55     # Detect method additions to Object and remove them in the
56     # BlankSlate class.
57     def method_added(name) #:nodoc:
58       blank_slate_method_added(name)
59       return if self != Object
60       Builder::BlankSlate.hide(name)
61     end
62   end
63 end