Skip to content

Commit

Permalink
Merge pull request #2 from pboling/patch-1
Browse files Browse the repository at this point in the history
Latest version of blank slate from Jim
  • Loading branch information
JackDanger committed Jun 13, 2014
2 parents 5a8c51b + f5b663d commit 9f0a2f8
Showing 1 changed file with 33 additions and 5 deletions.
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

0 comments on commit 9f0a2f8

Please sign in to comment.