-
-
Save jcf/215958 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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