Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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