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.
225 226 227 |
# File 'lib/olelo/extensions.rb', line 225 def /(path) "#{self}/#{path}".cleanpath end |
#cleanpath ⇒ String
Clean up path (replaces ‘..’, ‘.’ etc.)
203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/olelo/extensions.rb', line 203 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
195 196 197 |
# File 'lib/olelo/extensions.rb', line 195 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
186 187 188 |
# File 'lib/olelo/extensions.rb', line 186 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
172 173 174 175 176 177 178 179 |
# File 'lib/olelo/extensions.rb', line 172 def try_encoding(enc) old_enc = encoding if old_enc != enc force_encoding(enc) force_encoding(old_enc) if !valid_encoding? end self end |