Skip to content

Instantly share code, notes, and snippets.

@kungfumike
Created April 17, 2015 22:32
Show Gist options
  • Save kungfumike/72ff2eeefaa6a32c062f to your computer and use it in GitHub Desktop.
Save kungfumike/72ff2eeefaa6a32c062f to your computer and use it in GitHub Desktop.
I was wandering around a class I wrote five years ago...
# 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