He/Him/His
I'm a Software Engineer and a teacher.
There's no feeling quite like the one you get when you watch someone's eyes light up learning something they didn't know.
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.
Vicki, once a manager of aircraft maintenance, is now charming Python & Ruby. She has coded OpenGates.dev, #VetsWhoCode bot, Code Questions bot, & LGBTQ of the Day Bot. They love relatable writing.
Location
Richmond, Virginia
Education
Self Taught Python/Ruby, BBA in Small Business Mgmt, AS in Production Mgmt
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.
He/Him/His
I'm a Software Engineer and a teacher.
There's no feeling quite like the one you get when you watch someone's eyes light up learning something they didn't know.
Vicki, once a manager of aircraft maintenance, is now charming Python & Ruby. She has coded OpenGates.dev, #VetsWhoCode bot, Code Questions bot, & LGBTQ of the Day Bot. They love relatable writing.
Location
Richmond, Virginia
Education
Self Taught Python/Ruby, BBA in Small Business Mgmt, AS in Production Mgmt
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 ofnumber
directly as an integer, so callingto_i
on it is unnecessary.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.
It still works with the
to_i
, it's just unnecessary.All it does is convert an integer to an integer, no harm done 🙃
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.