[macruby-changes] [5162] MacRuby/trunk/vm_method.c

source_changes at macosforge.org source_changes at macosforge.org
Thu Jan 13 07:32:03 PST 2011


Revision: 5162
          http://trac.macosforge.org/projects/ruby/changeset/5162
Author:   watson1978 at gmail.com
Date:     2011-01-13 07:31:57 -0800 (Thu, 13 Jan 2011)
Log Message:
-----------
Module#method_defined? will return false when was passed name of private 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
}}}

Modified Paths:
--------------
    MacRuby/trunk/vm_method.c

Modified: MacRuby/trunk/vm_method.c
===================================================================
--- MacRuby/trunk/vm_method.c	2011-01-13 03:01:23 UTC (rev 5161)
+++ MacRuby/trunk/vm_method.c	2011-01-13 15:31:57 UTC (rev 5162)
@@ -265,7 +265,18 @@
 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))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20110113/a471a052/attachment.html>


More information about the macruby-changes mailing list