Skip to content

Commit

Permalink
Check float type before coerce to Integer
Browse files Browse the repository at this point in the history
  • Loading branch information
LTe committed Aug 27, 2012
1 parent 98f56f0 commit 5e927f6
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions kernel/common/random19.rb
Expand Up @@ -14,6 +14,9 @@ def random(limit)
else
if limit.kind_of?(Range)
random_range(limit)
elsif limit.kind_of?(Float)
raise ArgumentError, "invalid argument - #{limit}" if limit <= 0
random_float * limit
else
limit_int = Rubinius::Type.coerce_to limit, Integer, :to_int
raise ArgumentError, "invalid argument - #{limit}" if limit_int <= 0
Expand Down

0 comments on commit 5e927f6

Please sign in to comment.