Class: String
Direct Known Subclasses
Defined Under Namespace
Classes: HtmlString
Instance Method Summary collapse
-
#/(path) ⇒ String
Concatenate path components with /.
-
#cleanpath ⇒ String
Clean up path (replaces ‘..’, ‘.’ etc.).
-
#ends_with?(s) ⇒ Boolean
Check if string ends with s.
- #html_safe ⇒ Object
-
#starts_with?(s) ⇒ Boolean
Check if string starts with s.
-
#try_encoding(enc) ⇒ Object
Try to force encoding.
Instance Method Details
#/(path) ⇒ String
Concatenate path components with /
Calls #cleanpath on result.
222 223 224 |
# File 'lib/olelo/extensions.rb', line 222 def /(path) "#{self}/#{path}".cleanpath end |
#cleanpath ⇒ String
Clean up path (replaces ‘..’, ‘.’ etc.)
200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/olelo/extensions.rb', line 200 def cleanpath names = [] split('/').each do |name| case name when '..' names.pop when '.' when '' else names.push name end end names.join('/') end |
#ends_with?(s) ⇒ Boolean
Check if string ends with s
192 193 194 |
# File 'lib/olelo/extensions.rb', line 192 def ends_with?(s) rindex(s) == size - s.size end |
#html_safe ⇒ Object
22 23 24 |
# File 'lib/olelo/html_safe.rb', line 22 def html_safe HtmlString.new(self) end |
#starts_with?(s) ⇒ Boolean
Check if string starts with s
183 184 185 |
# File 'lib/olelo/extensions.rb', line 183 def starts_with?(s) index(s) == 0 end |
#try_encoding(enc) ⇒ Object
Try to force encoding
Force encoding of string and revert to original encoding if string has no valid encoding
169 170 171 172 173 174 175 176 |
# File 'lib/olelo/extensions.rb', line 169 def try_encoding(enc) old_enc = encoding if old_enc != enc force_encoding(enc) force_encoding(old_enc) if !valid_encoding? end self end |