remove String#has_suffix? monkey-patch; use String#end_with?

This commit is contained in:
Josh Holtrop 2014-02-14 10:20:32 -05:00
parent b43c473762
commit fa7d17675b
4 changed files with 6 additions and 17 deletions

View File

@ -46,8 +46,8 @@ module Rscons
end
def produces?(target, source, env)
target.has_suffix?(env['OBJSUFFIX']) and KNOWN_SUFFIXES.find do |compiler, suffix_var|
source.has_suffix?(env[suffix_var])
target.end_with?(*env['OBJSUFFIX']) and KNOWN_SUFFIXES.find do |compiler, suffix_var|
source.end_with?(*env[suffix_var])
end
end
@ -58,7 +58,7 @@ module Rscons
'_DEPFILE' => target.set_suffix('.mf'),
})
com_prefix = KNOWN_SUFFIXES.find do |compiler, suffix_var|
sources.first.has_suffix?(env[suffix_var])
sources.first.end_with?(*env[suffix_var])
end.tap do |v|
v.nil? and raise "Error: unknown input file type: #{sources.first.inspect}"
end.first

View File

@ -21,9 +21,9 @@ module Rscons
return false unless objects
ld = if env["LD"]
env["LD"]
elsif sources.find {|s| s.has_suffix?(env["DSUFFIX"])}
elsif sources.find {|s| s.end_with?(*env["DSUFFIX"])}
env["DC"]
elsif sources.find {|s| s.has_suffix?(env["CXXSUFFIX"])}
elsif sources.find {|s| s.end_with?(*env["CXXSUFFIX"])}
env["CXX"]
else
env["CC"]

View File

@ -254,7 +254,7 @@ module Rscons
# Return a list of the converted file names.
def build_sources(sources, suffixes, cache, vars)
sources.map do |source|
if source.has_suffix?(suffixes)
if source.end_with?(*suffixes)
source
else
converted = nil

View File

@ -1,16 +1,5 @@
# 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.