Module: JB3::Util
- Extended by:
 - Color
 
- Defined in:
 - lib/jb3.rb
 
Defined Under Namespace
Modules: Color
Class Method Summary collapse
- 
  
    
      .omit(hash, keys)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Omit keys from a hash.
 - 
  
    
      .omit!(hash, keys)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Same as #omit, but all keys are validated.
 - .one(array) ⇒ Object
 - .slice!(hash, keys) ⇒ Object
 
Methods included from Color
bold, green, grey, light_blue, light_grey, magenta, red, yellow
Class Method Details
.omit(hash, keys) ⇒ Object
Omit keys from a hash
      43 44 45  | 
    
      # File 'lib/jb3.rb', line 43 def self.omit(hash, keys) hash.reject { |key,| keys.include?(key) } end  | 
  
.omit!(hash, keys) ⇒ Object
Same as #omit, but all keys are validated.
      48 49 50 51 52 53 54 55 56  | 
    
      # File 'lib/jb3.rb', line 48 def self.omit!(hash, keys) keys.each do |key| next if hash.key?(key) raise("Expected #{key.inspect} to exist in target hash!") end omit(hash, keys) end  | 
  
.one(array) ⇒ Object
      58 59 60 61 62  | 
    
      # File 'lib/jb3.rb', line 58 def self.one(array) return array.first if array.one? raise SizeError, array.size end  | 
  
.slice!(hash, keys) ⇒ Object
      64 65 66 67 68  | 
    
      # File 'lib/jb3.rb', line 64 def self.slice!(hash, keys) hash.slice(*keys).tap do |slice| raise "Expected #{keys - slice.keys} to be present" unless slice.size.equal?(keys.size) end end  |