[macruby-changes] [2433] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Sat Aug 29 17:36:23 PDT 2009
Revision: 2433
http://trac.macosforge.org/projects/ruby/changeset/2433
Author: eloy.de.enige at gmail.com
Date: 2009-08-29 17:36:19 -0700 (Sat, 29 Aug 2009)
Log Message:
-----------
When dispatching to method_missing remove the trailing colon from the selector, unless the selector contains multiple colons making it certainly not be a traditional Ruby method.
Modified Paths:
--------------
MacRuby/trunk/vm.cpp
Added Paths:
-----------
MacRuby/trunk/spec/macruby/core/kernel_spec.rb
Added: MacRuby/trunk/spec/macruby/core/kernel_spec.rb
===================================================================
--- MacRuby/trunk/spec/macruby/core/kernel_spec.rb (rev 0)
+++ MacRuby/trunk/spec/macruby/core/kernel_spec.rb 2009-08-30 00:36:19 UTC (rev 2433)
@@ -0,0 +1,21 @@
+require File.dirname(__FILE__) + "/../spec_helper"
+
+describe "Kernel#method_missing, the selector passed as the method argument" do
+ before :all do
+ @obj = Object.new
+ def @obj.method_missing(m, *a, &b)
+ m
+ end
+ end
+
+ it "has the last colon stripped off if it's the only colon in the selector" do
+ @obj.foo.should == :foo
+ @obj.foo('bar').should == :foo
+ @obj.foo('bar', 'baz').should == :foo
+ end
+
+ it "is passed in as a full selector if it contains multiple colons" do
+ @obj.foo('bar', bar:'baz').should == :'foo:bar:'
+ @obj.foo('bar', bar:'baz', baz:'bla').should == :'foo:bar:baz:'
+ end
+end
\ No newline at end of file
Modified: MacRuby/trunk/vm.cpp
===================================================================
--- MacRuby/trunk/vm.cpp 2009-08-29 20:34:25 UTC (rev 2432)
+++ MacRuby/trunk/vm.cpp 2009-08-30 00:36:19 UTC (rev 2433)
@@ -2429,8 +2429,20 @@
char buf[100];
int n = snprintf(buf, sizeof buf, "%s", sel_getName(sel));
- if (argc <= 1 && buf[n - 1] == ':') {
- buf[n - 1] = '\0';
+ if (buf[n - 1] == ':') {
+ // Let's see if there are more colons making this a real selector.
+ bool multiple_colons = false;
+ for (int i = 0; i < (n - 1); i++) {
+ if (buf[i] == ':') {
+ multiple_colons = true;
+ break;
+ }
+ }
+ if (!multiple_colons) {
+ // Not a typical multiple argument selector. So as this is probably a
+ // typical ruby method name, chop off the colon.
+ buf[n - 1] = '\0';
+ }
}
new_argv[0] = ID2SYM(rb_intern(buf));
MEMCPY(&new_argv[1], argv, VALUE, argc);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090829/4a4c1364/attachment-0001.html>
More information about the macruby-changes
mailing list