* vm_method.c: added documentation of protected/private methods.

[fix GH-1072]
* test/ruby/test_module.rb: added testcase for method_defined?
  [fix GH-1071]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52381 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
hsbt 2015-10-30 03:36:21 +00:00
Родитель 6f77d0a3aa
Коммит 8d4dff2c18
3 изменённых файлов: 39 добавлений и 13 удалений

Просмотреть файл

@ -1,3 +1,10 @@
Fri Oct 30 12:36:16 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* vm_method.c: added documentation of protected/private methods.
[fix GH-1072]
* test/ruby/test_module.rb: added testcase for method_defined?
[fix GH-1071]
Fri Oct 30 12:06:59 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* variable.c (rb_class_ivar_set): rename as class specific ivar

Просмотреть файл

@ -74,6 +74,14 @@ class TestModule < Test::Unit::TestCase
include Mixin
def user
end
def user2
end
protected :user2
def user3
end
private :user3
end
module Other
@ -442,8 +450,8 @@ class TestModule < Test::Unit::TestCase
end
def test_instance_methods
assert_equal([:user], User.instance_methods(false))
assert_equal([:user, :mixin].sort, User.instance_methods(true).sort)
assert_equal([:user, :user2], User.instance_methods(false))
assert_equal([:user, :user2, :mixin].sort, User.instance_methods(true).sort)
assert_equal([:mixin], Mixin.instance_methods)
assert_equal([:mixin], Mixin.instance_methods(true))
assert_equal([:cClass], (class << CClass; self; end).instance_methods(false))
@ -458,12 +466,17 @@ class TestModule < Test::Unit::TestCase
end
def test_method_defined?
assert_method_not_defined?(User, :wombat)
assert_method_defined?(User, :user)
assert_method_defined?(User, :mixin)
assert_method_not_defined?(User, :wombat)
assert_method_defined?(User, :user)
assert_method_defined?(User, :mixin)
assert !User.method_defined?(:wombat)
assert User.method_defined?(:mixin)
assert User.method_defined?(:user)
assert User.method_defined?(:user2)
assert !User.method_defined?(:user3)
assert !User.method_defined?("wombat")
assert User.method_defined?("mixin")
assert User.method_defined?("user")
assert User.method_defined?("user2")
assert !User.method_defined?("user3")
end
def module_exec_aux

Просмотреть файл

@ -1198,20 +1198,26 @@ rb_mod_undef_method(int argc, VALUE *argv, VALUE mod)
*
* module A
* def method1() end
* def protected_method1() end
* protected :protected_method1
* end
* class B
* def method2() end
* def private_method2() end
* private :private_method2
* end
* class C < B
* include A
* def method3() end
* end
*
* A.method_defined? :method1 #=> true
* C.method_defined? "method1" #=> true
* C.method_defined? "method2" #=> true
* C.method_defined? "method3" #=> true
* C.method_defined? "method4" #=> false
* A.method_defined? :method1 #=> true
* C.method_defined? "method1" #=> true
* C.method_defined? "method2" #=> true
* C.method_defined? "method3" #=> true
* C.method_defined? "protected_method1" #=> true
* C.method_defined? "method4" #=> false
* C.method_defined? "private_method2" #=> false
*/
static VALUE