Sha256: 96e70de14307681835c02a68e8384bd17640ac189adae2f2057c6651fddfb353

Contents?: true

Size: 635 Bytes

Versions: 17

Compression:

Stored size: 635 Bytes

Contents

# Standard Ruby String class.
class String
  # Check if the given string ends with any of the supplied suffixes
  # @param suffix [String, Array] The suffix to look for.
  # @return a true value if the string ends with one of the suffixes given.
  def has_suffix?(suffix)
    if suffix
      suffix = [suffix] if suffix.is_a?(String)
      suffix = suffix.flatten
      suffix.find {|s| self.end_with?(s)}
    end
  end

  # Return a new string with the suffix (dot character and extension) changed
  # to the given suffix.
  # @param suffix [String] The new suffix.
  def set_suffix(suffix = '')
    sub(/\.[^.]*$/, suffix)
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
rscons-0.2.2 lib/rscons/monkey/string.rb
rscons-0.2.1 lib/rscons/monkey/string.rb
rscons-0.2.0 lib/rscons/monkey/string.rb
rscons-0.1.0 lib/rscons/monkey/string.rb
rscons-0.0.14 lib/rscons/monkey/string.rb
rscons-0.0.13 lib/rscons/monkey/string.rb
rscons-0.0.12 lib/rscons/monkey/string.rb
rscons-0.0.11 lib/rscons/monkey/string.rb
rscons-0.0.10 lib/rscons/monkey/string.rb
rscons-0.0.9 lib/rscons/monkey/string.rb
rscons-0.0.8 lib/rscons/monkey/string.rb
rscons-0.0.7 lib/rscons/monkey/string.rb
rscons-0.0.6 lib/rscons/monkey/string.rb
rscons-0.0.5 lib/rscons/monkey/string.rb
rscons-0.0.4 lib/rscons/monkey/string.rb
rscons-0.0.3 lib/rscons/monkey/string.rb
rscons-0.0.2 lib/rscons/monkey/string.rb