Sha256: 7b853012c49962a4d8f21898b51c2512b7011a6b134c0604a77af899531531d9

Contents?: true

Size: 483 Bytes

Versions: 3

Compression:

Stored size: 483 Bytes

Contents

#--
# Adapted from rand.rb by:
# * Ilmari Heikkinen <mailto:kig@misfiring.net>
# * Christian Neukirchen <mailto:chneukirchen@gmail.com>
#++
class Hash
  # Delete a random key-value pair, returning the key.
  #
  #   require 'facet/hash/at_rand'
  #
  #   a = {:one => 1, :two => 2, :three => 3}
  #   a.pick_key!  #=> :two
  #   a            #=> {:one => 1, :three => 3}
  #
  def rand_key!
    k,v = rand_pair
    delete( k )
    return k
  end
  alias( :pick_key, :rand_key! )
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
facets-0.7.0 lib/facet/hash/rand_key%21.rb
facets-0.7.1 lib/facet/hash/rand_key%21.rb
facets-0.7.2 lib/facet/hash/rand_key%21.rb