lib/symbolmatrix/symbolmatrix.rb in symbolmatrix-0.0.1 vs lib/symbolmatrix/symbolmatrix.rb in symbolmatrix-1.0.0

- old
+ new

@@ -34,22 +34,13 @@ super key.to_sym end alias []= store - # Returns a hashed version of this SymbolMatrix, with all SymbolMatrix objects within recursively - # converted into hashes - def to_hash recursive = true - the_hash = {} - self.each do |key, value| - if value.is_a? SymbolMatrix and recursive - the_hash[key] = value.to_hash - else - the_hash[key] = value - end - end - return the_hash + # @deprecated Use #to.hash instead + def to_hash + Kernel.warn "[DEPRECATION]: #to_hash is deprecated, please use #to.hash instead" end # Merges the passed hash within self def merge! hash hash.each do |key, value| @@ -75,8 +66,29 @@ else self[sym] end end + # Merges this SymbolMatrix with another SymbolMatrix recursively + def recursive_merge hash + result = SymbolMatrix.new + self.keys.each do |key| + result[key] = self[key] + end + + hash.keys.each do |key| + if result.has_key? key + result[key] = result[key].recursive_merge hash[key] + else + result[key] = hash[key] + end + end + return result + end + class KeyNotDefinedException < RuntimeError; end class InvalidKeyException < RuntimeError; end end + +def SymbolMatrix *args + SymbolMatrix.new *args +end \ No newline at end of file