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.2.5 lib/ruco/core_ext/hash.rb
ruco-0.2.4 lib/ruco/core_ext/hash.rb
ruco-0.2.3 lib/ruco/core_ext/hash.rb
ruco-0.2.2 lib/ruco/core_ext/hash.rb
ruco-0.2.1 lib/ruco/core_ext/hash.rb
ruco-0.2.0 lib/ruco/core_ext/hash.rb
ruco-0.2.0.beta12 lib/ruco/core_ext/hash.rb
ruco-0.2.0.beta11 lib/ruco/core_ext/hash.rb
ruco-0.2.0.beta10 lib/ruco/core_ext/hash.rb
ruco-0.2.0.beta9 lib/ruco/core_ext/hash.rb
ruco-0.2.0.beta8 lib/ruco/core_ext/hash.rb
ruco-0.2.0.beta7 lib/ruco/core_ext/hash.rb
ruco-0.2.0.beta6 lib/ruco/core_ext/hash.rb
ruco-0.2.0.beta5 lib/ruco/core_ext/hash.rb
ruco-0.2.0.beta4 lib/ruco/core_ext/hash.rb
ruco-0.2.0.beta3 lib/ruco/core_ext/hash.rb
ruco-0.2.0.beta2 lib/ruco/core_ext/hash.rb
ruco-0.2.0.beta lib/ruco/core_ext/hash.rb
ruco-0.1.14 lib/ruco/core_ext/hash.rb
ruco-0.1.13 lib/ruco/core_ext/hash.rb