Actions
Bug #16609
closed`#sample` not working with blocks properly
Bug #16609:
`#sample` not working with blocks properly
Description
This may be a bug, it may be an uncoded/partially working feature. Running #sample with a block doesn't complain or throw an error; The following code runs, but doesn't execute correctly.
a = [1, 2, 3, 4, 5, 6]
a.sample(&:even?) #=> 1 or 3 or 5 is **expected**
a.sample { |e| e.even? } #=> 1 or 3 or 5 is **expected**
But if you run the second snippet, you can get any number from 1 to 6. Here are a few runs:
a.sample
# => 3
a.sample(&:even?)
# => 1
a.sample(&:even?)
# => 2
a.sample(&:even?)
# => 6
a.sample(&:even?)
# => 3
a.sample(&:even?)
# => 2
Actions