diff options
author | Koichi Sasada <[email protected]> | 2021-11-13 02:15:09 +0900 |
---|---|---|
committer | Koichi Sasada <[email protected]> | 2021-11-15 15:58:56 +0900 |
commit | a24eeee5567a14841b37d9a3428e14e4f3c45c07 (patch) | |
tree | 0fde9df8d556581ba96f531c4a39ed3ae388f1e6 /array.rb | |
parent | b1b73936c15fd490159a9b30ab50b8d5dfea1264 (diff) |
Use `Primitive.mandatory_only?` for `Array#sample`
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5112
Diffstat (limited to 'array.rb')
-rw-r--r-- | array.rb | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -58,6 +58,12 @@ class Array # a.sample(random: Random.new(1)) #=> 6 # a.sample(4, random: Random.new(1)) #=> [6, 10, 9, 2] def sample(n = (ary = false), random: Random) - Primitive.rb_ary_sample(random, n, ary) + if Primitive.mandatory_only? + # Primitive.cexpr! %{ rb_ary_sample(self, rb_cRandom, Qfalse, Qfalse) } + Primitive.ary_sample0 + else + # Primitive.cexpr! %{ rb_ary_sample(self, random, n, ary) } + Primitive.ary_sample(random, n, ary) + end end end |