0

1)

- @client.getAvatars(@accountName).each do |avatar|
  =avatar['deleted']

输出:假假真

2)

- @client.getAvatars(@accountName).each do |avatar|
 - if(avatar['deleted'] == 'false')
   =avatar['deleted']

空输出

3)

- @client.getAvatars(@accountName).each do |avatar|
 - if(avatar['deleted'] != 'false')
   =avatar['deleted']

输出:假假真

我不明白它为什么如此奇怪,你能给我解释一下吗?

PS:我的工作变体是

- @client.getAvatars(@accountName).each do |avatar|
 - if(!avatar['deleted'])
   =avatar['deleted']

输出:假假

4

1 回答 1

6

我认为问题在于您认为avatar['deleted']返回一个字符串(单词“false”或单词“true”),而实际上返回的是一个布尔值。

试试这个代码:

- @client.getAvatars(@accountName).each do |avatar|
    - if(avatar['deleted'] == false) # or, if(avatar['deleted'])
        =avatar['deleted']

请注意,这false不是字符串,而是关键字:它是一个布尔标志。现在你应该得到与你的第一个场景更好地吻合的输出。

于 2012-06-15T14:43:14.963 回答