lib/core/facets/hash/inverse.rb in facets-2.1.3 vs lib/core/facets/hash/inverse.rb in facets-2.2.0

- old
+ new

@@ -1,32 +1,18 @@ -# TITLE: -# -# Hash Inverse -# -# SUMMARY: -# -# Create a "true" inverse hash by storing mutliple values -# in Arrays. -# -# CREDITS: -# -# - Tilo Sloboda - -# class Hash - # CREDIT Tilo Sloboda - # Create a "true" inverse hash by storing mutliple values # in Arrays. # # h = {"a"=>3, "b"=>3, "c"=>3, "d"=>2, "e"=>9, "f"=>3, "g"=>9} # # h.invert #=> {2=>"d", 3=>"f", 9=>"g"} # h.inverse #=> {2=>"d", 3=>["f", "c", "b", "a"], 9=>["g", "e"]} # h.inverse.inverse #=> {"a"=>3, "b"=>3, "c"=>3, "d"=>2, "e"=>9, "f"=>3, "g"=>9} # h.inverse.inverse == h #=> true + # + # CREDIT: Tilo Sloboda def inverse i = Hash.new self.each_pair{ |k,v| if (Array === v) @@ -37,30 +23,5 @@ } return i end end - - -# _____ _ -# |_ _|__ ___| |_ -# | |/ _ \/ __| __| -# | | __/\__ \ |_ -# |_|\___||___/\__| -# -=begin test - - require 'test/unit' - - class TestHashInverse < Test::Unit::TestCase - - def test_inverse - h1 = { :a=>1, :b=>2, :c=>2 } - h2 = h1.inverse - assert_equal( :a, h2[1] ) - assert( h2[2].include?(:b) ) - assert( h2[2].include?(:c) ) - end - - end - -=end