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
4 changes: 2 additions & 2 deletions core/numeric.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -668,8 +668,8 @@ class Numeric
# Numeric implements this by converting `self` to a Float and invoking
# Float#round.
#
def round: () -> Integer
| (Integer digits) -> Numeric
def round: (?half: round_mode) -> Integer
| (Integer digits, ?half: round_mode) -> Numeric

# <!--
# rdoc-file=numeric.c
Expand Down
17 changes: 17 additions & 0 deletions test/stdlib/Numeric_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,21 @@ def test_step
assert_send_type '(to: Rational, by: Float) { (Float) -> void } -> Rational',
1, :step, to: 3r, by: 0.2 do |i| break_from_block i end
end

class NumericWithToF < Numeric
def to_f = 2.5
end

def test_round
receiver = NumericWithToF.new

assert_send_type '() -> Integer',
receiver, :round
assert_send_type '(half: :even) -> Integer',
receiver, :round, half: :even
assert_send_type '(Integer) -> Numeric',
receiver, :round, 1
assert_send_type '(Integer, half: :down) -> Numeric',
receiver, :round, 1, half: :down
end
end
Loading