ruby-changes:40300
From: hsbt <ko1@a...>
Date: Fri, 30 Oct 2015 12:36:32 +0900 (JST)
Subject: [ruby-changes:40300] hsbt:r52381 (trunk): * vm_method.c: added documentation of protected/private methods.
hsbt 2015-10-30 12:36:21 +0900 (Fri, 30 Oct 2015) New Revision: 52381 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52381 Log: * 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] Modified files: trunk/ChangeLog trunk/test/ruby/test_module.rb trunk/vm_method.c Index: ChangeLog =================================================================== --- ChangeLog (revision 52380) +++ ChangeLog (revision 52381) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Fri Oct 30 12:36:16 2015 Nobuyoshi Nakada <nobu@r...> + + * 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@r...> * variable.c (rb_class_ivar_set): rename as class specific ivar Index: vm_method.c =================================================================== --- vm_method.c (revision 52380) +++ vm_method.c (revision 52381) @@ -1198,20 +1198,26 @@ rb_mod_undef_method(int argc, VALUE *arg https://github.com/ruby/ruby/blob/trunk/vm_method.c#L1198 * * 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 Index: test/ruby/test_module.rb =================================================================== --- test/ruby/test_module.rb (revision 52380) +++ test/ruby/test_module.rb (revision 52381) @@ -74,6 +74,14 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L74 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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L450 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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L466 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/