Question: How can I retrieve all keys in a Hash in Ruby, also the nested ones. Duplicates should be ignored, e.g.

```
{ a: 3, b: { b: 2, b: { c: 5 } } }.soberize
=> [:a, :b, :c]

```

What would be the fastest implementation?

Answer: 
Simple recursive solution:

```
def recursive_keys(data)
  data.keys + data.values.map{|value| recursive_keys(value) if value.is_a?(Hash) }
end

def all_keys(data)
  recursive_keys(data).flatten.compact.uniq
end 

```

Usage:

```
all_keys({ a: 3, b: { b: 2, b: { c: 5 } } })
=> [:a, :b, :c]

```
What about a recursive method?

```
def nested_keys(hash, array)
  if hash.is_a?(Hash)
    array |= hash.keys
    hash.keys.map do |key|
      array = nested_keys(hash[key], array)
    end
  end
  array
end

```