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.
我在这个变量里面@results有Tire::Results::Collection很多结果。
@results
Tire::Results::Collection
我怎样才能得到1 个随机结果Tire::Results::Collection
谢谢!
在 Ruby 1.9 上,只需使用以下Array#sample方法:
Array#sample
p [1, 2, 3].sample # ----- require 'tire' s = Tire.search { query { all } } p s.results.to_a.sample