Sha256: 800c4830b4deb6e543ca1d130a956ec4642c0c31d86a1da485a8ffab69013270
Contents?: true
Size: 700 Bytes
Versions: 4
Compression:
Stored size: 700 Bytes
Contents
# The Array class we all know and love. # class Array # Cluster-uniqs equal neighborly elements. # # Returns a copy. # def clustered_uniq self.inject([]) do |result, element| result << element if element != result.last result end end # Accesses a random element of this array. # # TODO Remove? # def random self[Kernel.rand(self.length)] end # Sort the array using distance from levenshtein. # # Will raise if encounters not to_s-able element. # def sort_by_levenshtein! from from = from.to_s sort! do |this, that| Text::Levenshtein.distance(this.to_s, from) <=> Text::Levenshtein.distance(that.to_s, from) end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
picky-0.9.3 | lib/picky/extensions/array.rb |
picky-0.9.2 | lib/picky/extensions/array.rb |
picky-0.9.1 | lib/picky/extensions/array.rb |
picky-0.9.0 | lib/picky/extensions/array.rb |