Skip to content

Commit

Permalink
Merge pull request #1783 from ksss/kernel-rand
Browse files Browse the repository at this point in the history
Fix Kernel.rand signature
  • Loading branch information
soutaro authored Apr 6, 2024
2 parents 8d59a72 + 95870d4 commit 8e50e4f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
8 changes: 4 additions & 4 deletions core/kernel.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -1318,10 +1318,10 @@ module Kernel : BasicObject
#
# See also Random.rand.
#
def self?.rand: () -> Float
| (Integer arg0) -> Integer
| (::Range[Integer] arg0) -> Integer
| (::Range[Float] arg0) -> Float
def self?.rand: (?0) -> Float
| (int arg0) -> (Integer | Float)
| (::Range[Integer] arg0) -> Integer?
| (::Range[Float] arg0) -> Float?

# <!--
# rdoc-file=io.c
Expand Down
13 changes: 13 additions & 0 deletions test/stdlib/Kernel_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@ def test_autoload?
Kernel, :autoload?, interned
end
end

def test_rand
assert_send_type "() -> Float", Kernel, :rand
assert_send_type "(0) -> Float", Kernel, :rand, 0
assert_send_type "(_ToInt) -> Float", Kernel, :rand, 0.0
assert_send_type "(_ToInt) -> Float", Kernel, :rand, 0r
assert_send_type "(_ToInt) -> Float", Kernel, :rand, 0i
assert_send_type "(_ToInt) -> Integer", Kernel, :rand, 10
assert_send_type "(Range[Integer]) -> Integer", Kernel, :rand, 1..10
assert_send_type "(Range[Integer]) -> nil", Kernel, :rand, 0...0
assert_send_type "(Range[Float]) -> Float", Kernel, :rand, 0.0...10.0
assert_send_type "(Range[Float]) -> nil", Kernel, :rand, 0.0...0.0
end
end

class KernelTest < StdlibTest
Expand Down

0 comments on commit 8e50e4f

Please sign in to comment.