Sha256: a35db39a60a7a57f4af6d9dd968bba8caea76dbbdebd58f82fd5967f5e51b80c
Contents?: true
Size: 936 Bytes
Versions: 1
Compression:
Stored size: 936 Bytes
Contents
require 'facet/array/store' class Array # Modifies #[] to accept an Array of indexes. # # require 'facet/array/[[]]' # # a = ['a','b','c','d','e','f'] # # a[[1]] #=> ['b'] # a[[1,1]] #=> ['b','b'] # a[[1,-1]] #=> ['b','f'] # a[[0,2,4]] #=> ['a','c','e'] # def [](*args) return values_at(*args.at(0)) if Array === args.at(0) return slice(*args) end # Modifies #[]= to accept an Array of indexes for assignment. # # require 'facet/array/[[]]' # # a = ['a','b','c','d'] # # a[[1]] = 'x' #=> ['x'] # a #=> ['a','x','c','d'] # # a[[1,-1]] = ['m','n'] #=> ['m','n'] # a #=> ['a','m','c','n'] # def []=(*args) if Array === args.at(0) idx = args.shift idx.each{ |i| store(i,args[i]) } return values_at( *idx ) else return store(*args) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
facets-0.6.3 | lib/facet/array/[[]].rb |