mirror of
https://github.com/zhigang1992/ProMotion.git
synced 2026-05-15 07:37:21 +08:00
Update to use more efficient array_all_members_of? method.
This commit is contained in:
@@ -132,7 +132,7 @@ module ProMotion
|
||||
|
||||
def update_table_data(args = {})
|
||||
# Try and detect if the args param is a NSIndexPath or an array of them
|
||||
args = { index_paths: args } if args.is_a?(NSIndexPath) || (args.is_a?(Array) && array_all_members_of(args, NSIndexPath))
|
||||
args = { index_paths: args } if args.is_a?(NSIndexPath) || (args.is_a?(Array) && array_all_members_of?(args, NSIndexPath))
|
||||
|
||||
self.update_table_view_data(self.table_data, args)
|
||||
self.promotion_table_data.search(search_string) if searching?
|
||||
|
||||
@@ -10,9 +10,8 @@ module ProMotion
|
||||
end
|
||||
|
||||
# Determines if all members of an array are a certain class
|
||||
def array_all_members_of(arr, kalss)
|
||||
unique_classes = arr.map(&:class).uniq
|
||||
(unique_classes.count == 1 && unique_classes.first == kalss)
|
||||
def array_all_members_of?(arr, kalss)
|
||||
arr.select{ |e| e.is_a?(klass) }.length == arr.length
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -23,12 +23,12 @@ describe "PM::Table utils" do
|
||||
end
|
||||
|
||||
it "should properly determine if all members of an array are the same class" do
|
||||
@subject.array_all_members_of([1, 2, 3, 4], Fixnum).should == true
|
||||
@subject.array_all_members_of(["string", 'string2'], String).should == true
|
||||
@subject.array_all_members_of([:sym1, :sym2, :sym3], Symbol).should == true
|
||||
@subject.array_all_members_of?([1, 2, 3, 4], Fixnum).should == true
|
||||
@subject.array_all_members_of?(["string", 'string2'], String).should == true
|
||||
@subject.array_all_members_of?([:sym1, :sym2, :sym3], Symbol).should == true
|
||||
|
||||
@subject.array_all_members_of([1, 2, 3, 4, 'String'], Fixnum).should == false
|
||||
@subject.array_all_members_of([4.4, 2], Fixnum).should == false
|
||||
@subject.array_all_members_of?([1, 2, 3, 4, 'String'], Fixnum).should == false
|
||||
@subject.array_all_members_of?([4.4, 2], Fixnum).should == false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user