Skip to content

Instantly share code, notes, and snippets.

@jcf
Forked from toreriklinnerud/ZippyHash.rb
Created October 22, 2009 13:59
Show Gist options
  • Save jcf/215958 to your computer and use it in GitHub Desktop.
Save jcf/215958 to your computer and use it in GitHub Desktop.
class Enumerable
# Like map/collect, but generates a Hash.
# The block is expected to return two values: the key and the value for the new hash.
def graph(&yld)
inject({}) do |h, *kv|
r = *yld[*kv]
nk, nv = *r
h[nk] = nv
h
end
end
end
def build_message
message = PORTFOLIO_FIELDS.graph{|field, _| [field, send(field)] }
self.message = message.delete_if { |_, value| value.nil? }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment