Sha256: 8681fec534b136b615bff3f8db0502212fd41bab06a92dba4804db202eddd678

Contents?: true

Size: 489 Bytes

Versions: 5

Compression:

Stored size: 489 Bytes

Contents

class Hash
  def depth
      a = self.to_a
      d = 1
      while (a.flatten!(1).map! {|e| (e.is_a? Hash) ? e.to_a.flatten(1) : (e.is_a? Array) ? e : nil}.compact!.size > 0)
          d += 1
      end
      d
  end

  def delete_blank
    delete_if do |_, v|
      (v.respond_to?(:empty?) ? v.empty? : !v) or v.instance_of?(Hash) && v.delete_blank.empty?
    end
  end
end

class Array
  def depth
    a = self.to_a
    return 0 unless a.is_a?(Array)
    return 1 + depth(a[0])
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
vagrant-invade-0.6.4 lib/vagrant-invade/extend.rb
vagrant-invade-0.6.3 lib/vagrant-invade/extend.rb
vagrant-invade-0.6.2 lib/vagrant-invade/extend.rb
vagrant-invade-0.6.1 lib/vagrant-invade/extend.rb
vagrant-invade-0.6.0 lib/vagrant-invade/extend.rb