Module: TaintedHash::RailsMethods

Defined in:
lib/tainted_hash.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



264
265
266
# File 'lib/tainted_hash.rb', line 264

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.



273
274
275
276
277
278
# File 'lib/tainted_hash.rb', line 273

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



280
281
282
283
284
# File 'lib/tainted_hash.rb', line 280

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_keysObject



286
287
288
# File 'lib/tainted_hash.rb', line 286

def stringify_keys
  self
end

#to_query(*args) ⇒ Object



290
291
292
# File 'lib/tainted_hash.rb', line 290

def to_query(*args)
  @original_hash.to_query(*args)
end