Sha256: 7f81a979b133d4cb4ed5feaaa82316b0b26c6d7874bf868a20dc634eb520d668
Contents?: true
Size: 584 Bytes
Versions: 3
Compression:
Stored size: 584 Bytes
Contents
class Array # Should be in the std library. # # keys = [:one, :two, :three] # vals = [1, 2, 3] # # keys.zip(vals).to_hash # #=> {:two=>2, :three=>3, :one=>1}}) # # keys.to_hash(vals) # #=> {:two=>2, :three=>3, :one=>1}}) def to_hash(vals=nil) a = vals ? self.zip(vals) : self a.inject({}) {|hash, i| hash[i[0]] = i[1]; hash} end # randomizes the order of contents in the Array (self) def randomize self.sort_by{ rand } end # Returns a randomly chosen element from self. def rand_elem self[rand(self.count)] end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rbkb-0.7.2 | lib/rbkb/extends/array.rb |
rbkb-0.7.1 | lib/rbkb/extends/array.rb |
rbkb-0.7.0 | lib/rbkb/extends/array.rb |