Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/core_ext/string.rb

Instance Method Summary collapse

Instance Method Details

#add_or_replace_uri_param(param_name, param_value) ⇒ Object


16
17
18
19
20
21
22
23
# File 'lib/core_ext/string.rb', line 16

def add_or_replace_uri_param(param_name, param_value)
  uri = URI(self)
  params = URI.decode_www_form(uri.query || '')
  params.delete_if { |param| param[0].to_s == param_name.to_s }
  params << [param_name, param_value]
  uri.query = URI.encode_www_form(params)
  uri.to_s
end

#add_uri_param(param_name, param_value) ⇒ Object


9
10
11
12
13
14
# File 'lib/core_ext/string.rb', line 9

def add_uri_param(param_name, param_value)
  uri = URI(self)
  params = URI.decode_www_form(uri.query || '') << [param_name, param_value]
  uri.query = URI.encode_www_form(params)
  uri.to_s
end

#to_boolObject


5
6
7
# File 'lib/core_ext/string.rb', line 5

def to_bool
  self == 'true'
end