class String

Public Instance Methods

query_string_to_hash() click to toggle source

Convert http query string to hash

# File lib/aliyunoss/extension.rb, line 12
def query_string_to_hash
  hash = Hash.new
  self.split('&').each do |q|
    if q["="]
      k,v = q.split('=')
      hash[k] = v
    else
      hash[q] = nil
    end
  end
  hash
end
underscore() click to toggle source

Convert CamelCase to ruby_case

# File lib/aliyunoss/extension.rb, line 26
def underscore
  self.gsub(/::/, '/').
    gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
    gsub(/([a-z\d])([A-Z])/,'\1_\2').
    tr("-", "_").
    downcase
end