Adam Vandenberg e6bac8a8ea back-port start_with? from 1.8.7
This allows its use in Leopard, which has Ruby 1.8.6.
2011-06-19 21:32:37 -07:00

38 lines
966 B
Ruby

class String
def undent
gsub(/^.{#{slice(/^ +/).length}}/, '')
end
unless String.method_defined?(:start_with?)
def start_with? prefix
prefix = prefix.to_s
self[0, prefix.length] == prefix
end
end
end
# used by the inreplace function (in utils.rb)
module StringInreplaceExtension
# Looks for Makefile style variable defintions and replaces the
# value with "new_value", or removes the definition entirely.
def change_make_var! flag, new_value
new_value = "#{flag}=#{new_value}"
gsub! Regexp.new("^#{flag}[ \\t]*=[ \\t]*(.*)$"), new_value
end
# Removes variable assignments completely.
def remove_make_var! flags
flags.each do |flag|
# Also remove trailing \n, if present.
gsub! Regexp.new("^#{flag}[ \\t]*=(.*)$\n?"), ""
end
end
# Finds the specified variable
def get_make_var flag
m = match Regexp.new("^#{flag}[ \\t]*=[ \\t]*(.*)$")
return m[1] if m
return nil
end
end