3 # Copyright 2004 by Jim Weirich (jim@weirichhouse.org).
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.
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).
20 # Hide the method named +name+ in the BlankSlate class. Don't
21 # hide +instance_eval+ or any method beginning with "__".
24 instance_methods.include?(name.to_s) and
25 name !~ /^(__|instance_eval)/
29 instance_methods.each { |m| hide(m) }
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:
39 alias_method :blank_slate_method_added, :method_added
41 # Detect method additions to Kernel and remove them in the
43 def method_added(name)
44 blank_slate_method_added(name)
45 return if self != Kernel
46 Builder::BlankSlate.hide(name)
53 alias_method :blank_slate_method_added, :method_added
55 # Detect method additions to Object and remove them in the
57 def method_added(name) #:nodoc:
58 blank_slate_method_added(name)
59 return if self != Object
60 Builder::BlankSlate.hide(name)