Sha256: 0afadf4d5ad243e8e94715db69b945a8b5fdb657f51c94b237d5776b6cfc05e3

Contents?: true

Size: 1.09 KB

Versions: 23

Compression:

Stored size: 1.09 KB

Contents

class Hash

  def to_http_str
    result = ''
    return result if self.empty?
    self.each do |key, val|
      result << "#{key}=#{URI.encode(val.to_s)}&"
    end
    result.chop
  end

  def symbolize_keys!
    self.each do |key, value|
      unless self.delete(key.to_s).nil?
        if value.is_a?(Hash)
          value.symbolize_keys!
        elsif value.is_a?(Array)
          value.map!{ |v| v.symbolize_keys! if v.is_a?(Hash) }
        end
        self[key.to_sym] = value
      end
    end  
    self
  end

  def stringfy_keys!
    self.each do |key, value|
      unless self.delete(key.to_sym).nil?
        if value.is_a?(Hash)
          value.stringfy_keys!
        elsif value.is_a?(Array)
          value.map!{ |v| v.stringfy_keys! if v.is_a?(Hash) }
        end
        self[key.to_s] = value
      end
    end  
    self  
  end

  def stringfy_values!
    self.each do |key, value|
      if value.is_a?(Hash)
        value.stringfy_values!
      elsif value.is_a?(Array)
        value.map!{ |v| v.stringfy_values! if v.is_a?(Hash) }
      end
      self[key] = value.to_s
    end  
    self
  end

end

Version data entries

23 entries across 23 versions & 4 rubygems

Version Path
nov-iknow-0.1.0 lib/ext/hash.rb
nov-iknow-0.1.1 lib/ext/hash.rb
nov-iknow-0.2.0 lib/ext/hash.rb
nov-iknow-0.2.2 lib/ext/hash.rb
nov-iknow-0.2.3 lib/ext/hash.rb
nov-iknow-0.2.4 lib/ext/hash.rb
nov-smartfm-0.4.0 lib/ext/hash.rb
nov-smartfm-0.4.1 lib/ext/hash.rb
nov-smartfm-1.0.0 lib/ext/hash.rb
nov-smartfm-1.0.2 lib/ext/hash.rb
iknow-0.1.1 lib/ext/hash.rb
iknow-0.1.0 lib/ext/hash.rb
iknow-0.2.1 lib/ext/hash.rb
iknow-0.2.3 lib/ext/hash.rb
iknow-0.2.4 lib/ext/hash.rb
iknow-0.2.0 lib/ext/hash.rb
iknow-0.2.2 lib/ext/hash.rb
smartfm-0.3.0 lib/ext/hash.rb
smartfm-1.0.1 lib/ext/hash.rb
smartfm-0.3.1 lib/ext/hash.rb