小编den*_*den的帖子

Ruby 3.1 中数组索引的奇怪行为

我不知道为什么我的红宝石中会发生这种情况,但是您看到同样的行为吗?

3.1.2 :001 > ["url", "label:from", "label:type", "label:batch", "note"].index('url')
 => nil
Run Code Online (Sandbox Code Playgroud)
3.1.2 :002 > ["url", "label:from", "label:type", "label:batch", "note"].index('note')
 => 4
Run Code Online (Sandbox Code Playgroud)
3.1.2 :003 > ["Url", "label:from", "label:type", "label:batch", "note"].index('Url')
 => 0
Run Code Online (Sandbox Code Playgroud)

小写时找不到“url”。这是保留字吗?

编辑:似乎无法找到第一次出现的“url”字符串:

["note", "url", "label:from", "label:type", "label:batch", "note", "url"].index 'url'
 => 6       
Run Code Online (Sandbox Code Playgroud)

ruby ruby-3.1

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

标签 统计

ruby ×1

ruby-3.1 ×1