Sha256: 7398e4bddac5b309ad202d4496e5b6fe8159e5ff7a36475c409427b9c2c5aaf4

Contents?: true

Size: 535 Bytes

Versions: 10

Compression:

Stored size: 535 Bytes

Contents

class Hash
  def subset *keys, &block
    keys = keys.first if keys.first.is_a? Array
    h = {}    
    if keys
      self.each do |k, v|
        h[k] = v if keys.include? k
      end
    else
      self.each do |k, v|
        h[k] = v if block.call k
      end
    end
    h
  end
    
  def validate_options! *valid_options
    unknown_options = keys - valid_options
    raise "unknown options :#{unknown_options.join(': ')}!" unless unknown_options.empty?
  end
  
  alias_method :blank?, :empty?
  alias_method :to_h, :to_hash
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ruby_ext-0.4.22 lib/ruby_ext/core/hash.rb
ruby_ext-0.4.21 lib/ruby_ext/core/hash.rb
ruby_ext-0.4.20 lib/ruby_ext/core/hash.rb
ruby_ext-0.4.19 lib/ruby_ext/core/hash.rb
ruby_ext-0.4.18 lib/ruby_ext/core/hash.rb
ruby_ext-0.4.17 lib/ruby_ext/core/hash.rb
ruby_ext-0.4.16 lib/ruby_ext/core/hash.rb
ruby_ext-0.4.15 lib/ruby_ext/core/hash.rb
ruby_ext-0.4.14 lib/ruby_ext/core/hash.rb
ruby_ext-0.4.13 lib/ruby_ext/core/hash.rb