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.4.0 lib/ruco/core_ext/hash.rb
ruco-0.3.0 lib/ruco/core_ext/hash.rb
ruco-0.2.23 lib/ruco/core_ext/hash.rb
ruco-0.2.22 lib/ruco/core_ext/hash.rb
ruco-0.2.21 lib/ruco/core_ext/hash.rb
ruco-0.2.20 lib/ruco/core_ext/hash.rb
ruco-0.2.19 lib/ruco/core_ext/hash.rb
ruco-0.2.18 lib/ruco/core_ext/hash.rb
ruco-0.2.17 lib/ruco/core_ext/hash.rb
ruco-0.2.16 lib/ruco/core_ext/hash.rb
ruco-0.2.15 lib/ruco/core_ext/hash.rb
ruco-0.2.14 lib/ruco/core_ext/hash.rb
ruco-0.2.13 lib/ruco/core_ext/hash.rb
ruco-0.2.12 lib/ruco/core_ext/hash.rb
ruco-0.2.11 lib/ruco/core_ext/hash.rb
ruco-0.2.10 lib/ruco/core_ext/hash.rb
ruco-0.2.9 lib/ruco/core_ext/hash.rb
ruco-0.2.8 lib/ruco/core_ext/hash.rb
ruco-0.2.7 lib/ruco/core_ext/hash.rb
ruco-0.2.6 lib/ruco/core_ext/hash.rb