Last active
August 29, 2015 14:17
-
-
Save a2ikm/b9e391744a30bef2c228 to your computer and use it in GitHub Desktop.
Array#rstrip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array | |
def rstrip | |
index = | |
if block_given? | |
rindex { |item| !yield(item) } | |
else | |
rindex { |item| !item.nil? } | |
end | |
if index | |
take(index) | |
else | |
dup | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment