lib/core/facets/array/index.rb in facets-2.4.4 vs lib/core/facets/array/index.rb in facets-2.4.5

- old
+ new

@@ -1,23 +1,48 @@ class Array if RUBY_VERSION < '1.9' - alias_method :facets_override_of_index, :index + alias_method :_facets_index, :index - #private :facets_override_of_index - # Allows #index to accept a block. # # OVERRIDE! This is one of the bery few core # overrides in Facets. # def index(obj=nil, &block) - return facets_override_of_index(obj) unless block_given? - i=0; i+=1 until yield(self[i]) - return i + if block_given? + _facets_index(find(&block)) + else + _facets_index(obj) + end end end end + + +=begin :spec: + + require 'quarry/spec' + + Quarry.spec "Array" do + + the_method "index" do + + finds "an element" do + i = [1,2,3].index{ |e| e == 2 } + i.assert == 1 + end + + terminates "when no element is found" do + i = [1,2,3].index{ |e| e == 5 } + i.assert == nil + end + + end + + end + +=end