1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Moved Array#shuffle and Array#shuffle! to rbinc

This commit is contained in:
Nobuyoshi Nakada 2020-01-26 18:27:40 +09:00
parent 0aa5195262
commit 29eb1b1602
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60
5 changed files with 53 additions and 54 deletions

36
array.rb Executable file
View file

@ -0,0 +1,36 @@
#!/usr/bin/ruby
class Array
# call-seq:
# ary.shuffle! -> ary
# ary.shuffle!(random: rng) -> ary
#
# Shuffles elements in +self+ in place.
#
# a = [ 1, 2, 3 ] #=> [1, 2, 3]
# a.shuffle! #=> [2, 3, 1]
# a #=> [2, 3, 1]
#
# The optional +rng+ argument will be used as the random number generator.
#
# a.shuffle!(random: Random.new(1)) #=> [1, 3, 2]
def shuffle!(random: Random)
__builtin_rb_ary_shuffle_bang(random)
end
# call-seq:
# ary.shuffle -> new_ary
# ary.shuffle(random: rng) -> new_ary
#
# Returns a new array with elements of +self+ shuffled.
#
# a = [ 1, 2, 3 ] #=> [1, 2, 3]
# a.shuffle #=> [2, 3, 1]
# a #=> [1, 2, 3]
#
# The optional +rng+ argument will be used as the random number generator.
#
# a.shuffle(random: Random.new(1)) #=> [1, 3, 2]
def shuffle(random: Random)
__builtin_rb_ary_shuffle(random);
end
end