summaryrefslogtreecommitdiff
path: root/array.rb
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2021-11-13 02:15:09 +0900
committerKoichi Sasada <ko1@atdot.net>2021-11-15 15:58:56 +0900
commita24eeee5567a14841b37d9a3428e14e4f3c45c07 (patch)
tree0fde9df8d556581ba96f531c4a39ed3ae388f1e6 /array.rb
parentb1b73936c15fd490159a9b30ab50b8d5dfea1264 (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.rb8
1 files changed, 7 insertions, 1 deletions
diff --git a/array.rb b/array.rb
index 05ce60773e..b9fa9844e6 100644
--- a/array.rb
+++ b/array.rb
@@ -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