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

delegate.rb: keep special methods

* lib/delegate.rb (Delegator): keep source information methods
  which start and end with '__'.  [ruby-core:58572] [Bug #9155]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44630 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-01-17 11:05:03 +00:00
parent 191b373d26
commit bcaec55695
3 changed files with 63 additions and 1 deletions

View file

@ -1,3 +1,8 @@
Fri Jan 17 20:05:02 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/delegate.rb (Delegator): keep source information methods
which start and end with '__'. [ruby-core:58572] [Bug #9155]
Fri Jan 17 17:58:04 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (rb_mod_s_constants): return its own constants for other

View file

@ -48,7 +48,7 @@ class Delegator < BasicObject
undef_method m
end
private_instance_methods.each do |m|
if /\Ablock_given\?\z|iterator\?\z|\A__raise__\z/ =~ m
if /\Ablock_given\?\z|iterator\?\z|\A__.*__\z/ =~ m
next
end
undef_method m

View file

@ -180,4 +180,61 @@ class TestDelegateClass < Test::Unit::TestCase
x = assert_nothing_raised(ArgumentError, bug9155) {break Bug9155.new(1)}
assert_equal(1, x.to_i, bug9155)
end
class Bug9403
Name = '[ruby-core:59718] [Bug #9403]'
SD = SimpleDelegator.new(new)
class << SD
def method_name
__method__
end
def callee_name
__callee__
end
alias aliased_name callee_name
def dir_name
__dir__
end
end
dc = DelegateClass(self)
dc.class_eval do
def method_name
__method__
end
def callee_name
__callee__
end
alias aliased_name callee_name
def dir_name
__dir__
end
end
DC = dc.new(new)
end
def test_method_in_simple_delegator
assert_equal(:method_name, Bug9403::SD.method_name, Bug9403::Name)
end
def test_callee_in_simple_delegator
assert_equal(:callee_name, Bug9403::SD.callee_name, Bug9403::Name)
assert_equal(:aliased_name, Bug9403::SD.aliased_name, Bug9403::Name)
end
def test_dir_in_simple_delegator
assert_equal(__dir__, Bug9403::SD.dir_name, Bug9403::Name)
end
def test_method_in_delegator_class
assert_equal(:method_name, Bug9403::DC.method_name, Bug9403::Name)
end
def test_callee_in_delegator_class
assert_equal(:callee_name, Bug9403::DC.callee_name, Bug9403::Name)
assert_equal(:aliased_name, Bug9403::DC.aliased_name, Bug9403::Name)
end
def test_dir_in_delegator_class
assert_equal(__dir__, Bug9403::DC.dir_name, Bug9403::Name)
end
end