You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classArray# Get the index of the first matching element relative to another index in an# array. Starts counting from the anchor index (which has index 0 in the# array slice used for the Array#index call). Like Array#index, may take a# block or a value.## %w[ a b c d e f g ].relative_index(4, :f) # => 1defrelative_index(anchor,val=nil, &block)subarray=self[anchor..-1]val ? subarray.index(val) : subarray.index(&block)endend
I made an issue for this b/c I don't see this particular definition being so useful. It's much clearer just to do the a[anchor..-1].index(foo) one's self. However maybe a more liberal definition could be more useful.
Activity
smackesey commentedon Jan 29, 2014
I think your criticism is correct. I'd modify your suggestion to solve the integer element problem by allowing the method to take a block:
This way, if you want to match an integer value, you can use a block to do so.