Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/useful_class_extensions.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
Instance Method Details
#flat_each(prefix = [], &blk) ⇒ Object
215 216 217 218 219 220 221 222 223 |
# File 'lib/useful_class_extensions.rb', line 215 def flat_each(prefix=[], &blk) each do |k,v| if v.is_a?(Hash) v.flat_each(prefix+[k], &blk) else yield prefix+[k], v end end end |
#flatify ⇒ Object
225 226 227 228 229 |
# File 'lib/useful_class_extensions.rb', line 225 def flatify hh = {} self.to_enum(:flat_each).collect { |k,v| [k.join("-"),v] }.collect {|attrib| hh[attrib[0]] = attrib[1]} return hh end |
#highest ⇒ Object
231 232 233 234 |
# File 'lib/useful_class_extensions.rb', line 231 def highest high_pair = self.max {|a,b| a[1] <=> b[1]} return {high_pair[0] => high_pair[1]} end |
#lowest ⇒ Object
236 237 238 239 |
# File 'lib/useful_class_extensions.rb', line 236 def lowest low_pair = self.min {|a,b| a[1] <=> b[1]} return {low_pair[0] => low_pair[1]} end |