extend/string: backport #rpartition

This commit is contained in:
Misty De Meo 2014-03-27 10:14:08 -07:00
parent a0851c1380
commit 38e26ed929

View File

@ -33,6 +33,15 @@ class String
end
end unless method_defined?(:end_with?)
# 1.8.7 or later; used in bottle code
def rpartition(separator)
if ind = rindex(separator)
[slice(0, ind), separator, slice(ind+1, -1) || '']
else
['', '', dup]
end
end unless method_defined?(:rpartition)
# String.chomp, but if result is empty: returns nil instead.
# Allows `chuzzle || foo` short-circuits.
def chuzzle