Skip to content

Commit

Permalink
fixed revealed method & block issue
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://rubyforge.org/var/svn/builder/trunk@114 b15df707-ad1a-0410-81b8-e991873a3486
  • Loading branch information
jimweirich committed Jun 16, 2008
1 parent d42aac2 commit ed7e5f0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
10 changes: 3 additions & 7 deletions lib/blankslate.rb
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions test/test_blankslate.rb
Expand Up @@ -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
Expand Down

0 comments on commit ed7e5f0

Please sign in to comment.