Sha256: 6b82ae49d288bf303cf5ae56e67cb3ee11e55d5bf405dffed3ad7f4b7f731fbc
Contents?: true
Size: 559 Bytes
Versions: 6
Compression:
Stored size: 559 Bytes
Contents
class Hash def fetch_path path path.split('/').drop(1).inject(self) do |hash, key| if scan = key.scan(/\[[\d+]\]/).first key.sub! scan, '' idx = scan.scan(/\d+/).first.to_i hash.respond_to?(:has_key?) && hash.has_key?(key) ? hash[key][idx] : break else hash.respond_to?(:has_key?) && hash.has_key?(key) ? hash[key] : break end end end def select_keys *keys select { |k, _| keys.include? k } end def has_entries? entries entries.each_pair.all? { |k, v| self[k] == v } end end
Version data entries
6 entries across 6 versions & 1 rubygems