Skip to content

Instantly share code, notes, and snippets.

@squarism
Created March 23, 2013 18:58
Show Gist options
  • Save squarism/5228986 to your computer and use it in GitHub Desktop.
Save squarism/5228986 to your computer and use it in GitHub Desktop.
Delete elements from a ruby array based on index
# I can't believe this works this elegantly.
a = [1,2,3,1,3,3,7]
# => [1, 2, 3, 1, 3, 3, 7]
a.reject.with_index {|element, i| i < 3}
# => [1, 3, 3, 7]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment