Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/aerogel/core/core_ext/hash.rb
Overview
Core extensions to Hash.
Instance Method Summary collapse
-
#except(*keys) ⇒ Object
Returns hash containing all elements except those with specified
keys
. -
#except!(*keys) ⇒ Object
Modifies and returns hash containing all elements except those with specified
keys
. -
#only(*keys) ⇒ Object
Returns hash containing only elements listed in
args
. -
#only!(*keys) ⇒ Object
Modifies and returns hash containing only elements listed in
args
. -
#to_html_params ⇒ Object
Returns Hash converted to a string of HTML tag attributes.
Instance Method Details
#except(*keys) ⇒ Object
Returns hash containing all elements except those with specified keys
.
24 25 26 |
# File 'lib/aerogel/core/core_ext/hash.rb', line 24 def except( *keys ) dup.except!( *keys ) end |
#except!(*keys) ⇒ Object
Modifies and returns hash containing all elements except those with specified keys
.
30 31 32 33 34 35 36 37 38 39 40 |
# 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) ⇒ Object
Returns hash containing only elements listed in args
.
11 12 13 |
# File 'lib/aerogel/core/core_ext/hash.rb', line 11 def only( *keys ) self.select{|key,v| [*keys].include? key } end |
#only!(*keys) ⇒ Object
Modifies and returns hash containing only elements listed in args
.
17 18 19 20 |
# 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 ⇒ Object
Returns Hash converted to a string of HTML tag attributes.
44 45 46 |
# 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 |