Skip to content
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

Merged
merged 3 commits into from Mar 30, 2013
Merged

Kernel.rand nearly passes the spec #515

merged 3 commits into from Mar 30, 2013

Conversation

jstepien
Copy link
Contributor

But it's not private yet.

But it's not private yet.
if max.is_a? Range
(max.last - max.first) * random + max.first
else
max = max.to_int.abs
Copy link
Member

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?

Copy link
Member

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jstepien
Copy link
Contributor Author

@kostya @timfel thanks for your comments. I'll return to this pull request once we've got block-less Fixnum#times, which depends on Enumerator. This will allow me to implement and run specs of Random#rand and in turn it will provide Kernel#rand for free.

@jstepien
Copy link
Contributor Author

Ready for a review, @alex.

alex added a commit that referenced this pull request Mar 30, 2013
Kernel.rand nearly passes the spec
@alex alex merged commit e42035a into topazproject:master Mar 30, 2013
@jstepien jstepien deleted the kernel-rand branch March 30, 2013 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants