Skip to content

Instantly share code, notes, and snippets.

@basicxman
Created May 7, 2011 05:25
Show Gist options
  • Select an option

  • Save basicxman/960223 to your computer and use it in GitHub Desktop.

Select an option

Save basicxman/960223 to your computer and use it in GitHub Desktop.
Ian wanted something to dynamically get sets of keys.
require 'pp'
$glob_store = []
def get_key_sets(temp, previous_set = nil)
temp.each_with_index do |value, index|
if previous_set.nil?
new_set = []
else
new_set = previous_set.dup
end
new_set << index
$glob_store << new_set
if value.is_a? Array
get_key_sets(value, new_set)
end
end
end
temp = [
[
[
9,
8,
[
9
]
]
],
[
0,
2,
4
]
]
get_key_sets(temp)
puts; puts; puts;
$glob_store.each do |key_set|
puts key_set.join("->")
end
puts; puts; puts;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment