1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

delegate.rb: refix r43682

* lib/delegate.rb (Delegator#send): separate from method_missing so
  that super calls proper method.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43727 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-11-19 16:27:40 +00:00
parent b9294f226b
commit a9a6c103e5
3 changed files with 26 additions and 1 deletions

View file

@ -1,3 +1,8 @@
Wed Nov 20 01:27:33 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/delegate.rb (Delegator#send): separate from method_missing so
that super calls proper method.
Tue Nov 19 23:38:49 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in (--with-os-version-style): option to transform target

View file

@ -74,7 +74,18 @@ class Delegator < BasicObject
$@.delete_if {|t| %r"\A#{Regexp.quote(__FILE__)}:#{__LINE__-2}:"o =~ t} if $@
end
end
alias send method_missing
#
# Handles the magic of delegation through \_\_getobj\_\_.
#
def send(m, *args, &block)
target = self.__getobj__
begin
target.respond_to?(m) ? target.__send__(m, *args, &block) : super(m, *args, &block)
ensure
$@.delete_if {|t| %r"\A#{Regexp.quote(__FILE__)}:#{__LINE__-2}:"o =~ t} if $@
end
end
#
# Checks for a method provided by this the delegate object by forwarding the

View file

@ -145,4 +145,13 @@ class TestDelegateClass < Test::Unit::TestCase
assert_nothing_raised(ArgumentError) {d.open}
assert_nothing_raised(ArgumentError) {d.send(:open)}
end
def test_send_method_in_delegator
d = Class.new(SimpleDelegator) do
def foo
"foo"
end
end.new(Object.new)
assert_equal("foo", d.send(:foo))
end
end