diff options
| author | Jack Nagel | 2013-07-19 22:32:56 -0500 |
|---|---|---|
| committer | Jack Nagel | 2013-07-19 22:32:57 -0500 |
| commit | b2c50ef57d590128043837c60b22fac1ad397140 (patch) | |
| tree | f82271fe1210b7d540112c03d88070ff6313fac5 /Library | |
| parent | 57ad4d40c54942668ddd471f92782eb43a7235b9 (diff) | |
| download | homebrew-b2c50ef57d590128043837c60b22fac1ad397140.tar.bz2 | |
Add String#end_with?
I'm tired of not remembering if start_with?/end_with? are portable, so
just add them both if they're not defined.
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/extend/string.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Library/Homebrew/extend/string.rb b/Library/Homebrew/extend/string.rb index b2a247297..7fe47d38e 100644 --- a/Library/Homebrew/extend/string.rb +++ b/Library/Homebrew/extend/string.rb @@ -24,6 +24,15 @@ class String end end unless method_defined?(:start_with?) + def end_with?(*suffixes) + suffixes.any? do |suffix| + if suffix.respond_to?(:to_str) + suffix = suffix.to_str + self[-suffix.length, suffix.length] == suffix + end + end + end unless method_defined?(:end_with?) + # String.chomp, but if result is empty: returns nil instead. # Allows `chuzzle || foo` short-circuits. def chuzzle |
