Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Array
- def count
- c = 0
- each { |e| c += 1 if yield e }
- return c
- end unless method_defined?(:count)
- def get_nth( n )
- c = 0
- each { |e| c += 1 if yield e ; return e if c == n }
- return nil
- end unless method_defined?(:get_nth)
- def get_nth_index( n )
- c = 0
- for i in 0...size
- e = self[i]
- c += 1 if yield e ; return i if c == n
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment