[macruby-changes] [4253] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Sat Jun 19 03:21:54 PDT 2010
Revision: 4253
http://trac.macosforge.org/projects/ruby/changeset/4253
Author: martinlagardette at apple.com
Date: 2010-06-19 03:21:53 -0700 (Sat, 19 Jun 2010)
Log Message:
-----------
Fixes using ruby `Array` methods on `SBElementArray`s
- When creating the new returned array, we should avoid using `-mutableCopy` because this doesn't work when using `SBElementArray`s
- Adding a spec, so that we make sure not to break this later
- Fixes #744
Modified Paths:
--------------
MacRuby/trunk/NSArray.m
MacRuby/trunk/spec/macruby/core/array_spec.rb
Modified: MacRuby/trunk/NSArray.m
===================================================================
--- MacRuby/trunk/NSArray.m 2010-06-19 05:19:07 UTC (rev 4252)
+++ MacRuby/trunk/NSArray.m 2010-06-19 10:21:53 UTC (rev 4253)
@@ -584,7 +584,8 @@
static id
nsary_reverse(id rcv, SEL sel)
{
- return nsary_reverse_bang([rcv mutableCopy], 0);
+ NSMutableArray *result = [NSMutableArray arrayWithArray:rcv];
+ return nsary_reverse_bang(result, 0);
}
static NSInteger
@@ -614,7 +615,8 @@
static id
nsary_sort(id rcv, SEL sel)
{
- return nsary_sort_bang([rcv mutableCopy], 0);
+ NSMutableArray *result = [NSMutableArray arrayWithArray:rcv];
+ return nsary_sort_bang(result, 0);
}
static VALUE
@@ -641,7 +643,8 @@
nsary_collect(id rcv, SEL sel)
{
RETURN_ENUMERATOR(rcv, 0, 0);
- return collect([rcv mutableCopy]);
+ NSMutableArray *result = [NSMutableArray arrayWithArray:rcv];
+ return collect(result);
}
static VALUE
@@ -763,7 +766,8 @@
nsary_reject(id rcv, SEL sel)
{
RETURN_ENUMERATOR(rcv, 0, 0);
- reject([rcv mutableCopy]);
+ NSMutableArray *result = [NSMutableArray arrayWithArray:rcv];
+ reject(result);
return (VALUE)rcv;
}
@@ -891,7 +895,7 @@
static id
nsary_uniq(id rcv, SEL sel)
{
- id result = [rcv mutableCopy];
+ id result = [NSMutableArray arrayWithArray:rcv];
nsary_uniq_bang(result, 0);
return result;
}
@@ -905,7 +909,7 @@
static id
nsary_compact(id rcv, SEL sel)
{
- id result = [rcv mutableCopy];
+ id result = [NSMutableArray arrayWithArray:rcv];
nsary_compact_bang(result, 0);
return result;
}
@@ -975,7 +979,7 @@
static id
nsary_shuffle(id rcv, SEL sel)
{
- id result = [rcv mutableCopy];
+ id result = [NSMutableArray arrayWithArray:rcv];
nsary_shuffle_bang(result, 0);
return result;
}
Modified: MacRuby/trunk/spec/macruby/core/array_spec.rb
===================================================================
--- MacRuby/trunk/spec/macruby/core/array_spec.rb 2010-06-19 05:19:07 UTC (rev 4252)
+++ MacRuby/trunk/spec/macruby/core/array_spec.rb 2010-06-19 10:21:53 UTC (rev 4253)
@@ -67,3 +67,17 @@
NSArray.arrayWithArray([1, 2, 42]).to_yaml.should == "--- \n- 1\n- 2\n- 42\n"
end
end
+
+# This test exists because the previous implementation of NSArray #map etc.
+# was using -mutableCopy to define the array to modify, which didn't work with
+# `SBElementArray`s. Let's make sure this keeps working
+describe "An SBElementArray (subclass of NSMutableArray)" do
+ it "responds to #map, #shuffle, etc." do
+ framework 'ScriptingBridge'
+ finder = SBApplication.applicationWithBundleIdentifier('com.apple.finder')
+ homeFolderItems = finder.home.items
+ lambda { homeFolderItems.map { |i| i.name } }.should_not raise_error(RuntimeError)
+ lambda { homeFolderItems.shuffle }.should_not raise_error(RuntimeError)
+ end
+end
+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100619/76d0d8df/attachment.html>
More information about the macruby-changes
mailing list