#--
# BlankSlate
#
# Copyright 2004 by Jim Weirich (jim@weirichhouse.org).
# All rights reserved.
#
# Permission is granted for use, copying, modification, distribution,
# and distribution of modified versions of this work as long as the
# above copyright notice is included.
#
# ==========================================================================
# Revision History ::
# --------------------------------------------------------------------------
# 2005.04.28 Trans * Ported to Mega Modules.
# ==========================================================================
#++
# :title: BlankSlate
#
# BlankSlate provides an abstract base class with no predefined
# methods (except for \_\_send__ and \_\_id__).
# BlankSlate is useful as a base class when writing classes that
# depend upon method_missing (e.g. dynamic proxies).
class BlankSlate
class << self
def hide(name)
undef_method name if
instance_methods.include?(name.to_s) and
name !~ /^(__|instance_eval)/
end
end
instance_methods.each { |m| hide(m) }
end
# Since Ruby is very dynamic, methods added to the ancestors of
# BlankSlate after BlankSlate is defined will show up in the
# list of available BlankSlate methods. We handle this by defining a hook
# in the Object and Kernel classes that will hide any defined.
module Kernel
class << self
alias_method :blank_slate_method_added, :method_added
def method_added(name)
blank_slate_method_added(name)
return if self != Kernel
BlankSlate.hide(name)
end
end
end
class Object
class << self
alias_method :blank_slate_method_added, :method_added
def method_added(name)
blank_slate_method_added(name)
return if self != Object
BlankSlate.hide(name)
end
end
end