Stdlib extensions
Methods
Public Instance methods
Will now accept a symbol or a block. Block behaves as before, symbol will be used as the property on which value to sort elements
[ show source ]
# File kirbybase_adapter.rb, line 1242
1242: def sort_by(*args, &bl)
1243: if not bl.nil?
1244: super &bl
1245: else
1246: super &lambda{ |item| item.send(args.first) }
1247: end
1248: end
Modifies the receiver - sorts in place by the given attribute / block
[ show source ]
# File kirbybase_adapter.rb, line 1236
1236: def sort_by!(*args, &bl)
1237: self.replace self.sort_by(*args, &bl)
1238: end
A stable sort - preserves the order in which elements were encountred. Used in multi-field sorts, where the second sort should preserve the order form the first sort.
[ show source ]
# File kirbybase_adapter.rb, line 1253
1253: def stable_sort
1254: n = 0
1255: sort_by {|x| n+= 1; [x, n]}
1256: end
Stable sort by a particular attribute.
[ show source ]
# File kirbybase_adapter.rb, line 1259
1259: def stable_sort_by(*args, &bl)
1260: n = 0
1261: if not bl.nil?
1262: super &bl
1263: sort_by { |item| n+=1; [bl[item], n] }
1264: else
1265: sort_by { |item| n+=1; [item.send(args.first), n] }
1266: end
1267: end