Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/rake.rb

Overview

User defined methods to be added to String.

Instance Method Summary collapse

Instance Method Details

#ext(newext = '') ⇒ Object

Replace the file extension with newext. If there is no extenson on the string, append the new extension to the end. If the new extension is not given, or is the empty string, remove any existing extension.

ext is a user added method for the String class.



78
79
80
81
82
83
84
# File 'lib/rake.rb', line 78

def ext(newext='')
  return self.dup if ['.', '..'].include? self
  if newext != ''
 	newext = (newext =~ /^\./) ? newext : ("." + newext)
  end
  dup.sub!(%r(([^/\\])\.[^./\\]*$)) { $1 + newext } || self + newext
end