lib/knj/arrayext.rb in knjrbfw-0.0.21 vs lib/knj/arrayext.rb in knjrbfw-0.0.22

- old
+ new

@@ -77,14 +77,28 @@ adds[key.to_sym] = value hash_given.delete(key) end end - adds.each do |key, value| - hash_given[key] = value + hash_given.merge!(adds) + + return hash_given + end + + #Converts all keys in the given hash to strings. + def self.hash_str(hash_given) + adds = {} + + hash_given.each do |key, val| + if !key.is_a?(String) + adds[key.to_s] = val + hash_given.delete(key) + end end + hash_given.merge!(adds) + return hash_given end def self.dict(arr) ret = Dictionary.new @@ -199,10 +213,10 @@ hash = hash.clone Knj::Php.foreach(hash) do |key, val| if val.is_a?(String) begin - hash[key] = Knj::Php.utf8_encode(encoding) + hash[key] = Knj::Php.utf8_encode(val) rescue Encoding::UndefinedConversionError => e if args["ignore_encoding_errors"] next else raise e \ No newline at end of file