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.1.12 lib/ruco/core_ext/hash.rb
ruco-0.1.11 lib/ruco/core_ext/hash.rb
ruco-0.1.10 lib/ruco/core_ext/hash.rb
ruco-0.1.9 lib/ruco/core_ext/hash.rb
ruco-0.1.8 lib/ruco/core_ext/hash.rb
ruco-0.1.7 lib/ruco/core_ext/hash.rb
ruco-0.1.6 lib/ruco/core_ext/hash.rb
ruco-0.1.5 lib/ruco/core_ext/hash.rb
ruco-0.1.4 lib/ruco/core_ext/hash.rb
ruco-0.1.3 lib/ruco/core_ext/hash.rb
ruco-0.1.2 lib/ruco/core_ext/hash.rb
ruco-0.1.1 lib/ruco/core_ext/hash.rb
ruco-0.1.0 lib/ruco/core_ext/hash.rb
ruco-0.0.56 lib/ruco/core_ext/hash.rb
ruco-0.0.55 lib/ruco/core_ext/hash.rb
ruco-0.0.54 lib/ruco/core_ext/hash.rb
ruco-0.0.53 lib/ruco/core_ext/hash.rb
ruco-0.0.52 lib/ruco/core_ext/hash.rb
ruco-0.0.51 lib/ruco/core_ext/hash.rb
ruco-0.0.50 lib/ruco/core_ext/hash.rb