Sha256: a786d737ce94ab1e0444ab263580e1d6e64bac7a5ba80c3193c346f6cf1c915a

Contents?: true

Size: 503 Bytes

Versions: 1

Compression:

Stored size: 503 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 :to_h, :to_hash
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby_ext-0.4.12 lib/ruby_ext/core/hash.rb