Class: String
Overview
String extension methods.
Instance Method Summary collapse
-
#/(o) ⇒ Object
Concatenates a path (do we really need this sugar?).
-
#uri_escape ⇒ Object
Encodes a normal string to a URI string.
-
#uri_unescape ⇒ Object
Decodes a URI string to a normal string.
Instance Method Details
#/(o) ⇒ Object
Concatenates a path (do we really need this sugar?)
15 16 17 |
# File 'lib/serverside/core_ext.rb', line 15 def /(o) File.join(self, o.to_s) end |
#uri_escape ⇒ Object
Encodes a normal string to a URI string.
4 5 6 7 |
# File 'lib/serverside/core_ext.rb', line 4 def uri_escape gsub(/([^ a-zA-Z0-9_.-]+)/n) {'%'+$1.unpack('H2'*$1.size). join('%').upcase}.tr(' ', '+') end |
#uri_unescape ⇒ Object
Decodes a URI string to a normal string.
10 11 12 |
# File 'lib/serverside/core_ext.rb', line 10 def uri_unescape tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/n){[$1.delete('%')].pack('H*')} end |