class String
Public Instance Methods
/(path)
click to toggle source
Concatenate path components with /
Calls {#cleanpath} on result.
@param [String] path component @return [String] this string concatenated with path
# File lib/olelo/extensions.rb, line 222 def /(path) "#{self}/#{path}".cleanpath end
cleanpath()
click to toggle source
Clean up path (replaces ‘..’, ‘.’ etc.)
@return [String] cleaned path
# 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)
click to toggle source
Check if string ends with s
@param [String] s @return [Boolean]
# File lib/olelo/extensions.rb, line 192 def ends_with?(s) rindex(s) == size - s.size end
html_safe()
click to toggle source
# File lib/olelo/html_safe.rb, line 22 def html_safe HtmlString.new(self) end
starts_with?(s)
click to toggle source
Check if string starts with s
@param [String] s @return [Boolean]
# File lib/olelo/extensions.rb, line 183 def starts_with?(s) index(s) == 0 end
try_encoding(enc)
click to toggle source
Try to force encoding
Force encoding of string and revert to original encoding if string has no valid encoding
@param [Encoding, String] enc New encoding @return self
# 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