lib/methodic_hash.rb in eymiha_util-0.1.3 vs lib/methodic_hash.rb in eymiha_util-0.1.4
- old
+ new
@@ -37,9 +37,22 @@
rescue
nil
end
end
+ # Deletes and returns the key-value pairs from hash whose keys are equal to
+ # key.to_s or key.to_sym. If both key.to_s and key.to_sym are in the hash,
+ # then both values are returned in an Array, respectively. If neither key is
+ # found, the delete is deferred to the Hash.
+ def delete(key,&block)
+ values = [key.to_s, key.to_sym].collect {|k| super(k){ nil } }.compact
+ case values.size
+ when 0 then super(key,&block)
+ when 1 then values[0]
+ when 2 then values
+ end
+ end
+
# A missing method is assummed to be the assignment of a value of a key, or
# the lookup of a value with a key.
def method_missing(method,*args)
string = method.to_s
if string[string.length-1,1] == '='