Permalink
Browse files

modify

  • Loading branch information...
1 parent 057717f commit 78857273f5feefe8ed6f1e3564ab4ac895955452 @ZhangHanDong committed Oct 26, 2010
Showing with 30 additions and 1 deletion.
  1. +2 −0 lib/ruby_extendsions.rb
  2. +27 −0 lib/ruby_extendsions/hash_extendsions.rb
  3. +1 −1 spec/hash_spec.rb
@@ -0,0 +1,2 @@
+require 'ruby_extendsions/hash_extendsions'
+
@@ -0,0 +1,27 @@
+module RubyExtendsions
+ module HashExtendsions
+ def self.included(base)
+ base.send :include, InstanceMethods
+ base.send :extend, ClassMethods
+ end
+
+ module InstanceMethods
+ def hash_reverse
+ hash_new = {}
+ self.each {|key,value|
+ if not hash_new.has_key?(key) then hash_new[value] = key end
+ }
+ return hash_new
+ end
+ end#InstanceMethods
+
+ module ClassMethods
+ #TODO
+ end#ClassMethods
+
+ end #HashExtendsions
+end #RubyExtendsions
+
+class Hash
+ include RubyExtendsions::HashExtendsions
+end
View
@@ -10,7 +10,7 @@
end
it "A hash data should be reversed" do
- require 'ruby_extend'
+ require 'ruby_extendsions'
@hash1.hash_reverse.should eql({1=>:a, 2=>:b} )
end
end

0 comments on commit 7885727

Please sign in to comment.