Skip to content

Instantly share code, notes, and snippets.

@kungfumike
Created April 17, 2015 22:30
Show Gist options
  • Save kungfumike/7b767142d07817e19045 to your computer and use it in GitHub Desktop.
Save kungfumike/7b767142d07817e19045 to your computer and use it in GitHub Desktop.
5 years ago vs today
# 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