David Anderson
Posts: 26
Nickname: tfhma
Registered: Oct, 2005
|
David Anderson is a software generalist in Cincinnati doing Ruby and Rails in the agile style.
|
|
|
|
A little Hash goodness
|
Posted: Sep 8, 2009 9:15 AM
|
|
|
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.
|
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by David Anderson
Latest Posts From def..end
|
|
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
Read: A little Hash goodness
|
|