Class: Hash

Inherits:
Object show all
Defined in:
lib/aliyun/oss/extensions.rb

Overview

:stopdoc:

Instance Method Summary collapse

Instance Method Details

#extractable_options?Boolean

By default, only instances of Hash itself are extractable. Subclasses of Hash may implement this method and return true to declare themselves as extractable. If a Hash is extractable, Array#extract_options! pops it from the Array when it is the last element of the Array.

Returns:

  • (Boolean)


10
11
12
# File 'lib/aliyun/oss/extensions.rb', line 10

def extractable_options?
  instance_of?(Hash)
end

#to_normalized_optionsObject



25
26
27
28
29
30
31
# File 'lib/aliyun/oss/extensions.rb', line 25

def to_normalized_options
  # Convert all option names to downcased strings, and replace underscores with hyphens
  inject({}) do |normalized_options, (name, value)|
    normalized_options[name.to_header] = value.to_s
    normalized_options
  end
end

#to_normalized_options!Object



33
34
35
# File 'lib/aliyun/oss/extensions.rb', line 33

def to_normalized_options!
  replace(to_normalized_options)
end

#to_query_string(include_question_mark = true) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/aliyun/oss/extensions.rb', line 14

def to_query_string(include_question_mark = true)
  query_string = ''
  unless empty?
    query_string << '?' if include_question_mark
    query_string << inject([]) do |params, (key, value)| 
      params << "#{key}=#{value}" 
    end.join('&')
  end
  query_string
end