“temps.each(&:valid?)"是什么意思?在 Ruby 中是什么意思? [英] What does "temps.each(&:valid?)" mean in Ruby?
本文介绍了“temps.each(&:valid?)"是什么意思?在 Ruby 中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能的重复:
map(&:name) 在 Ruby 中是什么意思?
each
中的 &:valid?
是什么意思?我见过 .each do |r|
或其他什么,但不知道这是如何工作的?
What does the &:valid?
found in the each
mean?
I've seen .each do |r|
or whatever, but not sure how this one works?
推荐答案
&
被称为 to_proc
操作符.它将符号 (:valid?
) 扩展为 Proc.所以你的例子相当于:
The &
is called the to_proc
operator. It expands the symbol (:valid?
) into a Proc.
So your example is equivalent to:
temps.each { |t| t.valid? }
这篇关于“temps.each(&:valid?)"是什么意思?在 Ruby 中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文