Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
**Ruby中的符号是什么意思?
**
(1..5).map { |i| i**2 } # => [1, 4, 9, 16, 25]
Fixnum#**是指数运算符。在您的示例中,您正在平方i(将其提高到 2 的幂)。
Fixnum#**
i
我从未使用过 Ruby,但从结果中我推断出这i**2意味着i^2(即i*i):
i**2
i^2
i*i
1*1 = 1
2*2 = 4
3*3 = 9
4*4 = 16
5*5 = 25