Method: Immutable::Vector#assoc
- Defined in:
- lib/immutable/vector.rb
#assoc(obj) ⇒ Object
Assumes all elements are nested, indexable collections, and searches through them, comparing obj with the first element of each nested collection. Return the first nested collection which matches, or nil if none is found. Behaviour is undefined when elements do not meet assumptions (i.e. are not indexable collections).
1263 1264 1265 1266 1267 1268 1269 |
# File 'lib/immutable/vector.rb', line 1263 def assoc(obj) each do |array| next if !array.respond_to?(:[]) return array if obj == array[0] end nil end |