Module: ForHashes
- Included in:
- Hash, OrderedHash
- Defined in:
- lib/shorthand.rb
Instance Method Summary collapse
- #clean ⇒ Object
- #hmap(&block) ⇒ Object
- #map_vals(&block) ⇒ Object
- #map_vals!(&block) ⇒ Object
- #stable_compact ⇒ Object
- #to_sig ⇒ Object
Instance Method Details
#clean ⇒ Object
335 |
# File 'lib/shorthand.rb', line 335 def clean() map_vals{|k,v| v.respond_to?(:clean) ? v.clean : (v.respond_to?(:to_str) ? v.to_str : v.to_s)} end |
#hmap(&block) ⇒ Object
334 |
# File 'lib/shorthand.rb', line 334 def hmap(&block) OrderedHash[*(self.map{|k,v| yield(k,v)}.compact.flatten)] end |
#map_vals(&block) ⇒ Object
333 |
# File 'lib/shorthand.rb', line 333 def map_vals(&block) dup.map_vals!(&block) end |
#map_vals!(&block) ⇒ Object
332 |
# File 'lib/shorthand.rb', line 332 def map_vals!(&block) each{|k,v| self[k] = yield(k,v)}; self end |
#stable_compact ⇒ Object
322 323 324 325 326 327 328 329 330 |
# File 'lib/shorthand.rb', line 322 def stable_compact() h = self.dup h = h.reject{|k,v| v.nil?} dat = h.map do |k,v| v = v.stable_compact if v.respond_to?(:stable_compact) [k.to_s, v] end dat.sort end |
#to_sig ⇒ Object
331 |
# File 'lib/shorthand.rb', line 331 def to_sig() stable_compact.inspect.to_sig end |