Николай обнови решението на 23.10.2011 20:25 (преди около 13 години)
+class Array
+ def to_hash
+ inject({}) { |hash, i| hash[i[0]] = i[1]; hash }
+ end
+end
+
+class Array
+ def index_by
+ inject({}) { |hash, word| hash[yield word] = word; hash }
+ end
+end
+
+class Array
+ def subarray_count(a)
+ count = 0
+ index = -1
+ while (index = self.join.index(a.join, index + 1))
+ count += 1
+ end
+ count
+ end
+end
+
+class Array
+ def occurences_count
+ a = inject({}) { |hash, word| hash[word] = self.count(word); hash }
+ a.default = 0
+ a
+ end
+end