New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kernel.rand nearly passes the spec #515
Conversation
But it's not private yet.
if max.is_a? Range | ||
(max.last - max.first) * random + max.first | ||
else | ||
max = max.to_int.abs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is to_int correct here, or should this use convert_type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, needs to do use convert_type
CRuby 1.9.3 >> class A
CRuby 1.9.3 ?> end
CRuby 1.9.3 => nil
CRuby 1.9.3 >> rand(A.new)
TypeError: can't convert A into Integer
from (irb):4:in `rand'
from (irb):4
from /home/tim/.rbenv/versions/ruby/bin/irb:12:in `<main>'
CRuby 1.9.3 >> class A
CRuby 1.9.3 ?> def to_int
CRuby 1.9.3 ?> 10
CRuby 1.9.3 ?> end
CRuby 1.9.3 ?> end
CRuby 1.9.3 => nil
CRuby 1.9.3 >> rand(A.new)
CRuby 1.9.3 => 6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ready for a review, @alex. |
Kernel.rand nearly passes the spec
But it's not private yet.