lib/ext/array.rb in terraformer-0.1.0 vs lib/ext/array.rb in terraformer-0.2.0
- old
+ new
@@ -1,6 +1,23 @@
class Array
+ def rotate_until &block
+ return if block[]
+ found = false
+ length.times do
+ push shift
+ if block[]
+ found = true
+ break
+ end
+ end
+ raise IndexError unless found
+ end
+
+ def rotate_until_first_equals obj
+ rotate_until { at(0) == obj }
+ end
+
def slice_exists? slice
start = slice.first
len = slice.size
each_with_index do |e, i|
return true if e == start && self[i,len] == slice