
On Wed, Nov 11, 2020 at 11:41:50AM +0800, Lu Weitao wrote:
On Wed, Nov 11, 2020 at 11:12:41AM +0800, Zhang Yu wrote:
program_version = @hash["#{program}_version"] || 'latest'
it's ok used in ruby, but will meet error in crystal, we can use like: program_version = @hash["#{program}_version"] ? @hash["#{program}_version"] : "latest" ^ This looks the same as || in ruby?
sorry, it's ruby grammar
for crystal: if key must exist, the value may be nil, we can use: program_version = @hash["#{program}_version"]? ? @hash["#{program}_version"] : "latest" if key does exist, we can use: program_version = @hash.has_key?("#{program}_version") ? @hash["#{program}_version"] : "latest" if key may be does exist or nil, we can sue: program_version = (@hash.has_key?("#{program}_version") && @hash["#{program}_version"]?) ? @hash["#{program}_version"] : "latest"
Good, thanks for the explanation, learned a lot. Thanks, Zhangyu