Joel Pearson wrote in post #1101264:
> There's probably a simpler way to lay this out, but this worked for me:
>
> def recursive_find( key, object )
>   case object
>   when Array
>     object.each do |el|
>       if el.is_a?(Hash) || el.is_a?(Array)
>         res = recursive_find( key, el )
>         return res if res
>       end
>     end
>   when Hash
>     return object[key] if object.has_key?( key )
>     object.each do |k,v|
>       if v.is_a?(Hash) || v.is_a?(Array)
>         res = recursive_find( key, v )
>         return res if res
>       end
>     end
>   end
>   nil
> end
>
> irb(main):022:0> recursive_find 'duration', h
> => 30

Joel,

I do have one question for you.  What happens when there are duplicate 
names in the response.  For ex. duration and uri appear in different 
arrays, so how would you specify which one you want?

-- 
Posted via http://www.ruby-forum.com/.