mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* vm_method.c (rb_method_boundp): Return false for protected
methods when called from Kernel#respond_to?. [ruby-dev:40461] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28543 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b2e340bf70
commit
78a78b45d6
4 changed files with 81 additions and 2 deletions
|
@ -1,3 +1,8 @@
|
|||
Mon Jul 5 16:05:39 2010 Akinori MUSHA <knu@iDaemons.org>
|
||||
|
||||
* vm_method.c (rb_method_boundp): Return false for protected
|
||||
methods when called from Kernel#respond_to?. [ruby-dev:40461]
|
||||
|
||||
Mon Jul 5 12:32:01 2010 Aaron Patterson <aaron@tenderlovemaking.com>
|
||||
|
||||
* ext/psych/lib/psych/scalar_scanner.rb (parse_string): support
|
||||
|
|
15
NEWS
15
NEWS
|
@ -8,6 +8,21 @@ Note that each entry is kept so brief that no reason behind or
|
|||
reference information is supplied with. For a full list of changes
|
||||
with all sufficient information, see the ChangeLog file.
|
||||
|
||||
== Changes since the 1.9.2 release
|
||||
=== Library updates (outstanding ones only)
|
||||
|
||||
* builtin classes
|
||||
|
||||
* Kernel
|
||||
|
||||
* Kernel#respond_to? now returns false for protected methods.
|
||||
|
||||
=== Compatibility issues (excluding feature bug fixes)
|
||||
|
||||
* Kernel#respond_to?
|
||||
|
||||
See above.
|
||||
|
||||
== Changes since the 1.9.1 release
|
||||
=== Library updates (outstanding ones only)
|
||||
|
||||
|
|
|
@ -39,6 +39,20 @@ class TestMethod < Test::Unit::TestCase
|
|||
def meth; end
|
||||
end
|
||||
|
||||
def mv1() end
|
||||
def mv2() end
|
||||
private :mv2
|
||||
def mv3() end
|
||||
protected :mv3
|
||||
|
||||
class Visibility
|
||||
def mv1() end
|
||||
def mv2() end
|
||||
private :mv2
|
||||
def mv3() end
|
||||
protected :mv3
|
||||
end
|
||||
|
||||
def test_arity
|
||||
assert_equal(0, method(:m0).arity)
|
||||
assert_equal(1, method(:m1).arity)
|
||||
|
@ -345,4 +359,48 @@ class TestMethod < Test::Unit::TestCase
|
|||
obj.extend(m)
|
||||
assert_equal([:m1, :a], obj.public_methods(false), bug)
|
||||
end
|
||||
|
||||
def test_visibility
|
||||
assert_equal('method', defined?(mv1))
|
||||
assert_equal('method', defined?(mv2))
|
||||
assert_equal('method', defined?(mv3))
|
||||
|
||||
assert_equal('method', defined?(self.mv1))
|
||||
assert_equal(nil, defined?(self.mv2))
|
||||
assert_equal('method', defined?(self.mv3))
|
||||
|
||||
assert_equal(true, respond_to?(:mv1))
|
||||
assert_equal(false, respond_to?(:mv2))
|
||||
assert_equal(false, respond_to?(:mv3))
|
||||
|
||||
assert_nothing_raised { mv1 }
|
||||
assert_nothing_raised { mv2 }
|
||||
assert_nothing_raised { mv3 }
|
||||
|
||||
assert_nothing_raised { self.mv1 }
|
||||
assert_raise(NoMethodError) { self.mv2 }
|
||||
assert_nothing_raised { self.mv3 }
|
||||
|
||||
v = Visibility.new
|
||||
|
||||
assert_equal('method', defined?(v.mv1))
|
||||
assert_equal(nil, defined?(v.mv2))
|
||||
assert_equal(nil, defined?(v.mv3))
|
||||
|
||||
assert_equal(true, v.respond_to?(:mv1))
|
||||
assert_equal(false, v.respond_to?(:mv2))
|
||||
assert_equal(false, v.respond_to?(:mv3))
|
||||
|
||||
assert_nothing_raised { v.mv1 }
|
||||
assert_raise(NoMethodError) { v.mv2 }
|
||||
assert_raise(NoMethodError) { v.mv3 }
|
||||
|
||||
assert_nothing_raised { v.__send__(:mv1) }
|
||||
assert_nothing_raised { v.__send__(:mv2) }
|
||||
assert_nothing_raised { v.__send__(:mv3) }
|
||||
|
||||
assert_nothing_raised { v.instance_eval { mv1 } }
|
||||
assert_nothing_raised { v.instance_eval { mv2 } }
|
||||
assert_nothing_raised { v.instance_eval { mv3 } }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -566,8 +566,9 @@ rb_method_boundp(VALUE klass, ID id, int ex)
|
|||
rb_method_entry_t *me = rb_method_entry(klass, id);
|
||||
|
||||
if (me != 0) {
|
||||
if ((ex & ~NOEX_RESPONDS) && (me->flag & NOEX_PRIVATE)) {
|
||||
return FALSE;
|
||||
if ((ex & NOEX_RESPONDS) && (me->flag & NOEX_PROTECTED) ||
|
||||
(ex & ~NOEX_RESPONDS) && (me->flag & NOEX_PRIVATE)) {
|
||||
return 0;
|
||||
}
|
||||
if (!me->def) return 0;
|
||||
if (me->def->type == VM_METHOD_TYPE_NOTIMPLEMENTED) {
|
||||
|
|
Loading…
Reference in a new issue