Sha256: 2051f573b444bb63c384c553b6342a0c5a3f1294ae9ce82aa0d56534c4c7f12c

Contents?: true

Size: 471 Bytes

Versions: 66

Compression:

Stored size: 471 Bytes

Contents

class Hash
  # 1.9 does not want index and 1.8 does not have key
  alias_method(:key, :index) unless method_defined?(:key)

  # http://www.ruby-forum.com/topic/149449
  def slice(*keys, &block)
    if block
      each do |key, val|
        boolean = block.call(key, val)
        keys << key if boolean
      end
    end
    hash = self
    keys.inject({}){|returned, key| returned.update key => hash[key]}
  end

  def reverse_merge(other)
    other.merge(self)
  end
end

Version data entries

66 entries across 66 versions & 1 rubygems

Version Path
ruco-0.0.49 lib/ruco/core_ext/hash.rb
ruco-0.0.48 lib/ruco/core_ext/hash.rb
ruco-0.0.47 lib/ruco/core_ext/hash.rb
ruco-0.0.46 lib/ruco/core_ext/hash.rb
ruco-0.0.45 lib/ruco/core_ext/hash.rb
ruco-0.0.44 lib/ruco/core_ext/hash.rb