print sentence.scan(/\[(\w+)\]/).all? do |word|
@words.keys.include? word[0].to_sym
end
我已经打印了 的各个值,@words.keys.include? word[0].to_sym
但它们并不都是真的,但它会打印true
. 我认为这可能是因为它的评估是这样的:
(print sentence.scan(/\[(\w+)\]/).all?) do |word|
@words.keys.include? word[0].to_sym
end
但我希望它评估为
print (sentence.scan(/\[(\w+)\]/).all? do |word|
@words.keys.include? word[0].to_sym
end)
但是,添加括号会导致
syntax error, unexpected keyword_do_block, expecting ')'
如何更改评估代码段的顺序?
编辑:
除非上述情况属实,否则我想返回 true 而不是 print,例如:
@sentences.reject do |sentence|
!(sentence.scan(/\[(\w+)\]/).all? { |word| @words.keys.include? word[0].to_sym })
end
但它拒绝一切。