Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/core_extensions.rb
Instance Method Summary collapse
- #filter_attributes(model) ⇒ Object
- #only(keypers) ⇒ Object
- #only!(keypers) ⇒ Object
- #symbolize_keys ⇒ Object
- #symbolize_keys! ⇒ Object
Instance Method Details
#filter_attributes(model) ⇒ Object
23 24 25 |
# File 'lib/core_extensions.rb', line 23 def filter_attributes(model) self.only(model.send(:attribute_names).map(&:to_sym)) end |
#only(keypers) ⇒ Object
14 15 16 |
# File 'lib/core_extensions.rb', line 14 def only(keypers) dup.only!(keypers) end |
#only!(keypers) ⇒ Object
18 19 20 21 |
# File 'lib/core_extensions.rb', line 18 def only!(keypers) self.select! {|k,v| keypers.include?(k)} self end |
#symbolize_keys ⇒ Object
3 4 5 |
# File 'lib/core_extensions.rb', line 3 def symbolize_keys dup.symbolize_keys! end |
#symbolize_keys! ⇒ Object
7 8 9 10 11 12 |
# File 'lib/core_extensions.rb', line 7 def symbolize_keys! keys.each do |key| self[(key.to_sym rescue key) || key] = delete(key) end self end |