Permalink
Browse files

! Fixes BlankSlate to work with 1.9.2

  • Loading branch information...
1 parent f75d989 commit 2f31ad49df869bcc652671111af8edd59004929b @kschiess kschiess committed Mar 7, 2011
Showing with 42 additions and 1 deletion.
  1. +2 −1 lib/blankslate.rb
  2. +38 −0 spec/blankslate_spec.rb
  3. +2 −0 spec/spec_helper.rb
View
@@ -20,7 +20,8 @@ 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.include?(name.to_s) and
+ methods = instance_methods.map(&:to_sym)
+ if methods.include?(name.to_sym) and
name !~ /^(__|instance_eval)/
@hidden_methods ||= {}
@hidden_methods[name.to_sym] = instance_method(name)
@@ -0,0 +1,38 @@
+require 'spec_helper'
+
+describe BlankSlate do
+ let(:blank_slate) { BlankSlate.new }
+
+ def call(obj, meth, *args)
+ BlankSlate.find_hidden_method(meth).bind(obj).call(*args)
+ end
+
+ describe "cleanliness" do
+ it "should not have many methods" do
+ BlankSlate.instance_methods.
+ map(&:to_s).sort.
+ should == ["__id__", "__send__", "instance_eval"]
+ end
+ end
+
+ context "when methods are added to Object" do
+ after(:each) {
+ class Object
+ undef :foo
+ end
+ }
+
+ it "should still be blank" do
+ class Object
+ def foo
+ end
+ end
+ Object.new.foo
+
+ lambda {
+ BlankSlate.new.foo
+ }.should raise_error(NoMethodError)
+ end
+
+ end
+end
View
@@ -0,0 +1,2 @@
+
+require 'blankslate'

0 comments on commit 2f31ad4

Please sign in to comment.