Sha256: b036770774e123fd33c4ad1dfc05f4c53a5cccc90d92d9d6bec40c3ca82192ad

Contents?: true

Size: 753 Bytes

Versions: 1

Compression:

Stored size: 753 Bytes

Contents

module NightcrawlerSwift
  module Hash

    unless {}.respond_to?(:symbolize_keys)
      def symbolize_keys
        {}.tap do |result|
          keys.each {|k| result[k.to_sym] = self[k]}
        end
      end

      def symbolize_keys!
        self.tap do
          keys.each {|k| self[k.to_sym] = delete(k)}
        end
      end
    end

    unless {}.respond_to?(:compact)
      def compact
        {}.tap do |result|
          keys.each {|k| result[k] = self[k] unless self[k].nil?}
        end
      end

      def compact!
        self.tap do
          keys.each do |k|
            value = delete(k)
            self[k] = value unless value.nil?
          end
        end
      end
    end

  end
end

Hash.send :include, NightcrawlerSwift::Hash

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nightcrawler_swift-0.6.0 lib/nightcrawler_swift/ext/hash.rb