Skip to content

Instantly share code, notes, and snippets.

@emiltin
Created April 20, 2010 12:55
Show Gist options
  • Save emiltin/372389 to your computer and use it in GitHub Desktop.
Save emiltin/372389 to your computer and use it in GitHub Desktop.
a = %w(2 3 4 2 5 6 1 1 6 2 4 5)
where = a.enum_with_index.map{ |v,i| i if v=="2"}.compact #build an array of positions
p a[where[0]+1..where[1]-1] #between 1. and 2. appearance
p a[where[1]+1..where[2]-1] #suppose you wanted items between 2. and 3. appearance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment