Permalink
Browse files

Module#method_defined? will return false when was passed name of priv…

…ate method.

Test Script:
{{{
require 'test/unit/assertions.rb'
include Test::Unit::Assertions

module Foo
  class Bar
    def public_method ; end

    protected
    def protected_method ; end

    private
    def private_method ; end
  end
end

assert_equal(true,  Foo::Bar.method_defined?("public_method"))
assert_equal(true,  Foo::Bar.method_defined?("protected_method"))
assert_equal(false, Foo::Bar.method_defined?("private_method"))
assert_equal(false, Foo::Bar.method_defined?(:private_method))

puts :ok
}}}

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@5162 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent 54992f2 commit 7beebf05fd235559bd9ca0f2766c8031ce766fdb @Watson1978 Watson1978 committed Jan 13, 2011
Showing with 12 additions and 1 deletion.
  1. +12 −1 vm_method.c
View
@@ -265,7 +265,18 @@ static VALUE
rb_mod_method_defined(VALUE mod, SEL sel, VALUE mid)
{
ID id = rb_to_id(mid);
- return rb_obj_respond_to2(Qnil, mod, id, true, false) ? Qtrue : Qfalse;
+ if (rb_obj_respond_to2(Qnil, mod, id, true, false)) {
+ rb_vm_method_node_t *node;
+ if (rb_vm_lookup_method2((Class)mod, id, NULL, NULL, &node)) {
+ if (node != NULL) {
+ if (node->flags & NOEX_PRIVATE) {
+ return Qfalse;
+ }
+ }
+ return Qtrue;
+ }
+ }
+ return Qfalse;
}
#define VISI_CHECK(x,f) (((x)&NOEX_MASK) == (f))

0 comments on commit 7beebf0

Please sign in to comment.