Created
January 9, 2012 15:18
-
-
Save pootsbook/1583368 to your computer and use it in GitHub Desktop.
Ever wanted Array#penultimate? How about Array#penpenultimate
This file contains hidden or 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 method_missing(method_sym, *arguments, &block) | |
if method_sym.to_s =~ /^((pen)+)ultimate$/ | |
pen_index = 1 + ($1.length/3) | |
self[-pen_index] | |
else | |
super | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment