我有一個方法返回分析值的哈希值。如果條件滿足,散列中的某些值我想成爲nil
,但是我無法在值中寫入條件。有條件地設置哈希密鑰的值
有沒有一種方法可以有條件地設置密鑰的值,而不需要散列之外的一串if
/else
聲明?
見asignee_handle:
及以下issue_closed_at:
:
def parse(issue)
{
github_id: issue['id'].to_i,
github_number: issue['number'].to_i,
github_url: issue['url'],
title: issue['title'],
body: issue['body'],
creator_handle: issue['user']['login'],
asignee_handle: issue['assignee']['login'] if issue['assignee'] #can't do this,
asignee_avatar_url: issue['assignee']['avatar_url'],
issue_created_at: issue['created_at'].to_datetime,
issue_updated_at: issue['updated_at'].to_datetime,
issue_closed_at: issue['closed_at'].to_datetime if issue['closed_at'],
repo: issue['url'].split('/')[5]
}
end
'asignee_handle:issue ['assignee']?問題['assignee'] ['login']:無' – Santhosh