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.
是否可以在 Crystal 中使用块的简写,例如
my_array.sort_by(&:size)
此尝试返回错误:
... 期望一个函数类型,而不是 Symbol
您可以使用以下语法:
my_array = ["123", "22", "1"] sorted = my_array.sort_by &.size puts sorted => ["1", "22", "123"]