class Hash

Core extensions to Hash.

Public Instance Methods

except( *keys ) click to toggle source

Returns hash containing all elements except those with specified keys.

# File lib/aerogel/core/core_ext/hash.rb, line 24
def except( *keys )
  dup.except!( *keys )
end
except!( *keys ) click to toggle source

Modifies and returns hash containing all elements except those with specified keys.

# File lib/aerogel/core/core_ext/hash.rb, line 30
def except!( *keys )
  keys.each do |k|
    if String === k || Symbol === k
     delete k.to_sym
     delete k.to_s
    else
      delete k
    end
  end
  self
end
only( *keys ) click to toggle source

Returns hash containing only elements listed in args.

# File lib/aerogel/core/core_ext/hash.rb, line 11
def only( *keys )
  self.select{|key,v| [*keys].include? key }
end
only!( *keys ) click to toggle source

Modifies and returns hash containing only elements listed in args.

# File lib/aerogel/core/core_ext/hash.rb, line 17
def only!( *keys )
  self.select!{|key,v| [*keys].include? key }
  self
end
to_html_params() click to toggle source

Returns Hash converted to a string of HTML tag attributes.

# File lib/aerogel/core/core_ext/hash.rb, line 44
def to_html_params
  self.map{|n, v| v.nil? ? "#{n}" : "#{n}=\"#{v}\""}.join(" ")
end