Avoid calling to_s on the same Pathname multiple times
This commit is contained in:
parent
1e2cb0fd65
commit
51bfd4fc1e
@ -122,17 +122,17 @@ class Pathname
|
|||||||
|
|
||||||
# extended to support common double extensions
|
# extended to support common double extensions
|
||||||
alias extname_old extname
|
alias extname_old extname
|
||||||
def extname
|
def extname(path=to_s)
|
||||||
BOTTLE_EXTNAME_RX.match to_s
|
BOTTLE_EXTNAME_RX.match(path)
|
||||||
return $1 if $1
|
return $1 if $1
|
||||||
/(\.(tar|cpio)\.(gz|bz2|xz|Z))$/.match to_s
|
/(\.(tar|cpio)\.(gz|bz2|xz|Z))$/.match(path)
|
||||||
return $1 if $1
|
return $1 if $1
|
||||||
return File.extname(to_s)
|
return File.extname(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
# for filetypes we support, basename without extension
|
# for filetypes we support, basename without extension
|
||||||
def stem
|
def stem
|
||||||
return File.basename(to_s, extname)
|
File.basename((path = to_s), extname(path))
|
||||||
end
|
end
|
||||||
|
|
||||||
# I don't trust the children.length == 0 check particularly, not to mention
|
# I don't trust the children.length == 0 check particularly, not to mention
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user