From 38e26ed92989a3c8611d6d7bfa8fea76e86452fd Mon Sep 17 00:00:00 2001 From: Misty De Meo Date: Thu, 27 Mar 2014 10:14:08 -0700 Subject: [PATCH] extend/string: backport #rpartition --- Library/Homebrew/extend/string.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Library/Homebrew/extend/string.rb b/Library/Homebrew/extend/string.rb index 7fe47d38e4..56126e247a 100644 --- a/Library/Homebrew/extend/string.rb +++ b/Library/Homebrew/extend/string.rb @@ -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