Module: TaintedHash::RailsMethods
- Defined in:
- lib/tainted_hash.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#slice(*keys) ⇒ Object
Public: Returns a portion of the Hash.
- #slice!(*keys) ⇒ Object
- #stringify_keys ⇒ Object
- #to_query ⇒ Object
Class Method Details
.included(base) ⇒ Object
260 261 262 |
# File 'lib/tainted_hash.rb', line 260 def self.included(base) base.send :alias_method, :stringify_keys!, :stringify_keys end |
Instance Method Details
#slice(*keys) ⇒ Object
Public: Returns a portion of the Hash.
*keys - One or more String keys.
Returns a Hash of the requested keys and values.
269 270 271 272 273 274 |
# File 'lib/tainted_hash.rb', line 269 def slice(*keys) keys.each_with_object(self.class.new) do |key, hash| key_s = key.to_s hash[key_s] = @original_hash[key_s] if @original_hash.key?(key_s) end end |
#slice!(*keys) ⇒ Object
276 277 278 279 280 |
# File 'lib/tainted_hash.rb', line 276 def slice!(*keys) str_keys = keys.map { |k| k.to_s } (@original_hash.keys - str_keys).each { |key| delete(key) } expose(*str_keys) end |
#stringify_keys ⇒ Object
282 283 284 |
# File 'lib/tainted_hash.rb', line 282 def stringify_keys self end |
#to_query ⇒ Object
286 287 288 |
# File 'lib/tainted_hash.rb', line 286 def to_query @original_hash.to_query end |