lib/facet/hash/rand_value.rb in facets-1.1.0 vs lib/facet/hash/rand_value.rb in facets-1.2.0
- old
+ new
@@ -1,60 +2 @@
-#--
-# Adapted from rand.rb by:
-# * Ilmari Heikkinen <mailto:kig@misfiring.net>
-# * Christian Neukirchen <mailto:chneukirchen@gmail.com>
-#++
-
-require 'facet/hash/rand_key'
-
-class Hash
-
- # Returns a random hash value.
- #
- # {:one => 1, :two => 2, :three => 3}.rand_value #=> 2
- # {:one => 1, :two => 2, :three => 3}.rand_value #=> 1
- #
- def rand_value
- fetch( rand_key )
- end
-
- # Deletes a random key-value pair and returns the value.
- #
- # a = {:one => 1, :two => 2, :three => 3}
- # a.at_rand! #=> 2
- # a #=> {:one => 1, :three => 3}
- #
- def rand_value!
- k,v = rand_pair
- delete( k )
- return v
- end
-
- alias_method( :pick, :rand_value! )
-
- alias_method( :at_rand, :rand_value )
- alias_method( :at_rand!, :rand_value! )
-
-
-end
-
-
-# _____ _
-# |_ _|__ ___| |_
-# | |/ _ \/ __| __|
-# | | __/\__ \ |_
-# |_|\___||___/\__|
-#
-=begin test
-
- require 'test/unit'
-
- class TCHash < Test::Unit::TestCase
-
- def test_rand_value
- h = { :a=>1, :b=>2, :c=>3 }
- 10.times { assert( h.values.include?( h.rand_value ) ) }
- end
-
- end
-
-=end
+require 'facets/core/hash/rand_value.rb'
\ No newline at end of file