Skip to content
Browse files

fixed revealed method & block issue

git-svn-id: svn+ssh://rubyforge.org/var/svn/builder/trunk@114 b15df707-ad1a-0410-81b8-e991873a3486
  • Loading branch information...
1 parent d42aac2 commit ed7e5f0e165a766c7707fd1ef8e2bb77597a859e jimweirich committed Jun 16, 2008
Showing with 16 additions and 7 deletions.
  1. +3 −7 lib/blankslate.rb
  2. +13 −0 test/test_blankslate.rb
View
10 lib/blankslate.rb
@@ -36,13 +36,9 @@ def find_hidden_method(name)
# Redefine a previously hidden method so that it may be called on a blank
# slate object.
def reveal(name)
- bound_method = nil
- unbound_method = find_hidden_method(name)
- fail "Don't know how to reveal method '#{name}'" unless unbound_method
- define_method(name) do |*args|
- bound_method ||= unbound_method.bind(self)
- bound_method.call(*args)
- end
+ hidden_method = find_hidden_method(name)
+ fail "Don't know how to reveal method '#{name}'" unless hidden_method
+ define_method(name, hidden_method)
end
end
View
13 test/test_blankslate.rb
@@ -155,6 +155,19 @@ def test_revealing_previously_hidden_methods_are_callable
assert_match /^#<.*>$/, with_to_s.new.to_s
end
+ def test_revealing_previously_hidden_methods_are_callable_with_block
+ Object.class_eval <<-EOS
+ def given_block(&block)
+ block
+ end
+ EOS
+
+ with_given_block = Class.new(BlankSlate) do
+ reveal :given_block
+ end
+ assert_not_nil with_given_block.new.given_block {}
+ end
+
def test_revealing_a_hidden_method_twice_is_ok
with_to_s = Class.new(BlankSlate) do
reveal :to_s

0 comments on commit ed7e5f0

Please sign in to comment.
Something went wrong with that request. Please try again.