0
<%= m.members %>

这会在下面返回这个数组。如果我只想获取这个数组的最后一行(Ray 的记录),我该如何编码?

[#<User id: 4, username: "John", age: 27, deleted_at: nil>, 
#<User id: 8, username: "Mike", age: 27, deleted_at: nil>,
#<User id: 13, username: "Ray", age: 27, deleted_at: nil>]
4

1 回答 1

1
[#<User id: 4, username: "John", age: 27, deleted_at: nil>, 
#<User id: 8, username: "Mike", age: 27, deleted_at: nil>,
#<User id: 13, username: "Ray", age: 27, deleted_at: nil>].last


如果我们想获取最后一个和第一个元素,如下所示:
例如:arr = [1,2,3,4]
$> arr.last => 4
$> arr.first => 1

于 2012-12-15T04:22:28.520 回答