DEV Community

loading...

Discussion on: More Ruby from a Python Dev

Collapse
yechielk profile image
Yechiel Kalmenson

Awesome post in an awesome series!

One point in the section on even numbers; you don't need to call .to_i if it's already a number.

I'm guessing you copy/pasted it from a sample where there number was received as user input using gets (in which case the input would come in as a string and would need to be converted to an integer explicitly), but in your example, you set the value of number directly as an integer, so calling to_i on it is unnecessary.

Collapse
vickilanger profile image
Vicki (she/her) Author

Oh dang! You’re right, when I took it out of my example, it didn’t need that anymore. I definitely had this after a gets

Guess I should’ve included the whole thing or at least test that line by itself. Thanks for bringing that up. I’d hate to reference back to this and not understand why it doesn’t work right.

Collapse
yechielk profile image
Yechiel Kalmenson

It still works with the to_i, it's just unnecessary.

All it does is convert an integer to an integer, no harm done 🙃

Thread Thread
vickilanger profile image
Vicki (she/her) Author

Fixed it up anyway. It goes to show my point of how succinct Ruby is in this case.

And my posts contain no copying and pasting from samples. I’d never learn anything that way. For this, I always make up my own stuff and use that.