Created
April 17, 2015 22:32
-
-
Save kungfumike/72ff2eeefaa6a32c062f to your computer and use it in GitHub Desktop.
I was wandering around a class I wrote five years ago...
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
# 5 years ago..... | |
if first.nil? | |
first_non_nil = compact.first | |
each_with_index{|val, i| | |
break if val | |
self[i] = first_non_nil | |
} | |
end | |
# Forwardfill | |
if last.nil? | |
last_non_nil = compact.last | |
reverse!.each_with_index{|val, i| | |
break if val | |
self[i] = last_non_nil | |
} | |
reverse! | |
end | |
# Re-factoring today... | |
self[0] = find_all {|x| !x.nil?}.first if first.nil? | |
self[(size - 1)] = find_all {|x| !x.nil?}.last if last.nil? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment