Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/creative_rails_utilities/hash.rb
Instance Method Summary collapse
- #fast_sort_keys ⇒ Object
-
#populate_with_keys(min: nil, max: nil, explicit_default_value: 0) ⇒ Object
TODO write fast sort values.
Instance Method Details
#fast_sort_keys ⇒ Object
3 4 5 6 |
# File 'lib/creative_rails_utilities/hash.rb', line 3 def fast_sort_keys keys = self.keys.sort Hash[keys.zip(self.values_at(*keys))] end |
#populate_with_keys(min: nil, max: nil, explicit_default_value: 0) ⇒ Object
TODO write fast sort values
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/creative_rails_utilities/hash.rb', line 10 def populate_with_keys(min: nil, max: nil, explicit_default_value: 0) start_key = min || self.keys.min end_key = max || self.keys.max result = self.dup (start_key..end_key).each do |k| result[k] = self[k] || explicit_default_value end return result end |