我只是想知道 Ruby 或 RnR 中是否有类似的东西?
这篇文章:Why no tail() or head() method in List to get last or first element? 谈论这个关于 Java 但我想知道同样的事情但是在 Ruby 或 RnR 中。
感谢您的宝贵时间!
最佳答案
这是一种可能性:
head, *tail = args
它使用 Ruby splat 运算符。
例子:
args = [1, 2, 3, 4, 5, 6, 7, 8]
# => [1, 2, 3, 4, 5, 6, 7, 8]
head, *tail = args
head
# => 1
tail
# => [2, 3, 4, 5, 6, 7, 8]
关于ruby-on-rails - 我想知道 Ruby 或 Ruby on Rails(框架)中是否有 Head- and Tail-methods,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22459091/