小编Jas*_*on 的帖子

.零?附加到数组时的值查询

我正在完成codecademy练习,我无法弄清楚.nil是什么?意味着我需要实施它.这是我的代码:

movies = { GIS: 10.0, Phantasm: 1.5, Bourne: 4.0}
puts "Whats your movie brah?"
title = gets.chomp
puts "What's your rating brah?"
rating = gets.chomp
movies[title] = rating
puts "Your info was totally saved brah!"
case movies
when 'add'
  puts "What movie do you want to add?"
  title = gets.chomp
  if movies[title.to_sym].nil?
    puts "What's the rating? (Type a number 0 to 4.)"
    rating = gets.chomp
    movies[title.to_sym] = rating.to_i
    puts "#{title} has been added with a rating of #{rating}."
  else …
Run Code Online (Sandbox Code Playgroud)

ruby null if-statement

1
推荐指数
1
解决办法
56
查看次数

标签 统计

if-statement ×1

null ×1

ruby ×1