This post originated from an RSS feed registered with Ruby Buzz
by David Anderson.
Original Post: A little Hash goodness
Feed Title: def..end
Feed URL: http://feeds.feedburner.com/Defend
Feed Description: Ruby, Rails, and a smattering of other cruft from the back of Dave's mind.
Some quick refactoring this weekend had me throwing together some tidbits.module Enumerable # return Hash of enumeration to yielded values def collect_hash hash={} inject(hash) {|h,e| h[e] = block_given? ? yield(e) : nil; h } end # return Hash of enumeration to non-nil yielded values def select_hash hash={}, &block collect_hash(hash,&block).compact endendclass Hash # return Hash with