[macruby-changes] [5146] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Sun Jan 9 21:02:15 PST 2011


Revision: 5146
          http://trac.macosforge.org/projects/ruby/changeset/5146
Author:   watson1978 at gmail.com
Date:     2011-01-09 21:02:10 -0800 (Sun, 09 Jan 2011)
Log Message:
-----------
Kernel#public_method will throw an exception when calls without public method.

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

class T
  def foo ; end
  protected :foo

  def bar ; end
  private :bar

  def baz ; end
end

a = [ 1, 2 ]
assert_nothing_raised{ a.public_method(:size) }

t = T.new
assert_raise(NameError){ t.public_method(:foo) }
assert_raise(NameError){ t.public_method(:bar) }
assert_nothing_raised  { t.public_method(:baz) }

puts :ok
}}}

Modified Paths:
--------------
    MacRuby/trunk/proc.c
    MacRuby/trunk/spec/frozen/tags/macruby/core/kernel/public_method_tags.txt

Modified: MacRuby/trunk/proc.c
===================================================================
--- MacRuby/trunk/proc.c	2011-01-09 04:13:03 UTC (rev 5145)
+++ MacRuby/trunk/proc.c	2011-01-10 05:02:10 UTC (rev 5146)
@@ -670,6 +670,26 @@
     rb_vm_method_t *m = rb_vm_get_method(klass, obj, id, scope);
     assert(m != NULL);
 
+    if (m->node) {
+	const int flag = m->node->flags & NOEX_MASK;
+	if (scope && flag != NOEX_PUBLIC) {
+	    const char *v = "";
+	    switch (flag) {
+	      case NOEX_PRIVATE:
+		v = "private";
+		break;
+	      case NOEX_PROTECTED:
+		v = "protected";
+		break;
+	    }
+	    rb_name_error(id, "method `%s' for %s `%s' is %s",
+			  rb_id2name(id),
+			  (TYPE(klass) == T_MODULE) ? "module" : "class",
+			  rb_class2name(klass),
+			  v);
+	}
+    }
+
     return Data_Wrap_Struct(mclass, NULL, NULL, m);
 }
 

Modified: MacRuby/trunk/spec/frozen/tags/macruby/core/kernel/public_method_tags.txt
===================================================================
--- MacRuby/trunk/spec/frozen/tags/macruby/core/kernel/public_method_tags.txt	2011-01-09 04:13:03 UTC (rev 5145)
+++ MacRuby/trunk/spec/frozen/tags/macruby/core/kernel/public_method_tags.txt	2011-01-10 05:02:10 UTC (rev 5146)
@@ -1,3 +1 @@
 fails:Kernel#public_method returns a method object if we repond_to_missing? method
-fails:Kernel#public_method raises a NameError when called on a private method
-fails:Kernel#public_method raises a NameError when called on a protected method
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20110109/a9945fa0/attachment.html>


More information about the macruby-changes mailing list