Paul Jungwirth
unread,May 26, 2016, 10:58:44 PM5/26/16Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to pdxruby
This question is a little fussy, but is there any way to embed a
conditional key+value pair inside a hash literal? I want to do
something like this:
{
a: 1,
b: nil,
*(c ? {c: c} : {})
}
Getting either `{a:1, b:nil}` or `{a:1, b:nil, c:c}` but not `{..., c:nil}`.
The analogy is `[*foo, *nil]` giving just `foo`.
Is this possible? If not, what is the nicest way to write it? I can't
just take out everything with a `nil` value, because I want to keep
`b: nil`.
Thanks!
Paul
--
_________________________________
Pulchritudo splendor veritatis.