Sha256: 6eb4f05e3f17d4b2f1ac1e0cb756358b6c6f9cc4112c8398b250236f896a556f

Contents?: true

Size: 618 Bytes

Versions: 7

Compression:

Stored size: 618 Bytes

Contents

require 'ostruct'

# Backport of 2.0.0 stdlib ostruct#to_h
class OpenStruct
  def to_h
    @table.dup
  end unless method_defined? :to_h
end

class Hash
  def stringify_values
    inject({}) do |options, (key, value)|
      options[key] = value.to_s
      options
    end
  end

  def compact
    select { |_, value| !value.nil? }
  end

  def deep_merge!(other_hash, &block)
    other_hash.each_pair do |k,v|
      tv = self[k]
      if tv.is_a?(Hash) && v.is_a?(Hash)
        self[k] = tv.deep_merge(v, &block)
      else
        self[k] = block && tv ? block.call(k, tv, v) : v
      end
    end
    self
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rack-tracker-1.0.1 lib/rack/tracker/extensions.rb
rack-tracker-1.0.0 lib/rack/tracker/extensions.rb
rack-tracker-0.4.2 lib/rack/tracker/extensions.rb
rack-tracker-0.4.1 lib/rack/tracker/extensions.rb
rack-tracker-0.4.0 lib/rack/tracker/extensions.rb
rack-tracker-0.3.0 lib/rack/tracker/extensions.rb
rack-tracker-0.2.6 lib/rack/tracker/extensions.rb