Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/array/includeeql.rb,
lib/array/selectindices.rb
Instance Method Summary collapse
-
#include_eql?(other) ⇒ Boolean
Whereas normal include? uses == method, this method uses eql? alternatively.
-
#select_indices ⇒ Object
Return sorted array of indices which a block returns true.
Instance Method Details
#include_eql?(other) ⇒ Boolean
Whereas normal include? uses == method, this method uses eql? alternatively.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/array/includeeql.rb', line 10 def include_eql?(other) result = false each do |i| if i.eql?(other) result ||= true break end end return result end |
#select_indices ⇒ Object
Return sorted array of indices which a block returns true.
9 10 11 12 13 14 15 |
# File 'lib/array/selectindices.rb', line 9 def select_indices results = [] each_with_index { |item, index| results << index if yield(item) } return results end |