Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/ratis/core_ext.rb

Instance Method Summary collapse

Instance Method Details

#to_array(*path) ⇒ Object

Traverses the Hash for a given path of Hash keys and returns the value as an Array. Defaults to return an empty Array in case the path does not exist or returns nil. Copied from Savon::SOAP::Response#to_array



7
8
9
10
11
12
13
14
# File 'lib/ratis/core_ext.rb', line 7

def to_array(*path)
  result = path.inject(self) do |memo, key|
    return [] unless memo[key]
    memo[key]
  end

  [result].compact.flatten(1)
end