Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Convert sub hashes of SuperHash into SuperHashes

  • Loading branch information...
commit e6049635239b24689c027829d7ea783ec29f538a 1 parent 58b346e
@quirkey authored
Showing with 20 additions and 1 deletion.
  1. +20 −1 lib/super_hash.rb
View
21 lib/super_hash.rb
@@ -9,6 +9,24 @@ def deep_merge(other_hash)
end
end
+ def [](key)
+ superify(super)
+ end
+
+ def self.superify(val)
+ if val.is_a?(Hash) && !val.is_a?(SuperHash)
+ SuperHash.new(val)
+ elsif val.is_a?(Array)
+ val.collect {|f| superify(f) }
+ else
+ val
+ end
+ end
+
+ def superify(val)
+ self.class.superify(val)
+ end
+
private
def method_missing(m,*a)
if m.to_s =~ /\?$/ && self.has_key?(m.to_s[0...-1])
@@ -17,9 +35,10 @@ def method_missing(m,*a)
if m.to_s =~ /=$/
self[$`] = a[0]
elsif a.empty?
- self[m.to_s]
+ self[m.to_s]
else
super
end
end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.