Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions lib/blankslate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,30 @@
# above copyright notice is included.
#++

class String
if instance_methods.first.is_a?(Symbol)
def _blankslate_as_name
to_sym
end
else
def _blankslate_as_name
self
end
end
end

class Symbol
if instance_methods.first.is_a?(Symbol)
def _blankslate_as_name
self
end
else
def _blankslate_as_name
to_s
end
end
end

######################################################################
# BlankSlate provides an abstract base class with no predefined
# methods (except for <tt>\_\_send__</tt> and <tt>\_\_id__</tt>).
Expand All @@ -16,16 +40,20 @@
#
class BlankSlate
class << self

# Hide the method named +name+ in the BlankSlate class. Don't
# hide +instance_eval+ or any method beginning with "__".
def hide(name)
if instance_methods.map(&:to_sym).include?(name.to_sym) and
name !~ /^(__|instance_eval|object_id)/
warn_level = $VERBOSE
$VERBOSE = nil
if instance_methods.include?(name._blankslate_as_name) &&
name !~ /^(__|instance_eval$)/
@hidden_methods ||= {}
@hidden_methods[name.to_sym] = instance_method(name)
undef_method name
end
ensure
$VERBOSE = warn_level
end

def find_hidden_method(name)
Expand All @@ -41,7 +69,7 @@ def reveal(name)
define_method(name, hidden_method)
end
end

instance_methods.each { |m| hide(m) }
end

Expand Down Expand Up @@ -106,4 +134,4 @@ def append_features(mod)
end
result
end
end
end