class String
Add extensions to the default class(String).
Public Instance Methods
ensure_ending!(ending)
click to toggle source
@param [String] ending
@raise [ArgumentError]
@return [String]
# File lib/ruuuby/extensions.rb, line 184 def ensure_ending!(ending) Ruuuby::Params::check_string(ending) return self if ending == '' || self.end_with?(ending) len_this = self.length return self << ending if len_this == 0 last_matched = '' len_ending = ending.length delta = 0 while delta <= len_this && delta <= len_ending ending_of_this = self[(len_this-1-delta)..(len_this-1)] starting_of_end = ending[0..delta] last_matched = starting_of_end if ending_of_this == starting_of_end delta += 1 end self << (last_matched == '' ? ending : ending[last_matched.length..len_ending-1]) end
ensure_ending_char!(ending)
click to toggle source
@param [String] ending
@raise [ArgumentError]
@return [String]
# File lib/ruuuby/extensions.rb, line 206 def ensure_ending_char!(ending) Ruuuby::Params::check_char(ending) self << ending if self.length == 0 || self[-1] != ending self end