Given a string object like this:
twohundred = "200"
What is the difference between doing:
Integer(twohundred) #=> 200
and:
twohundred.to_i #=> 200
Is there any difference? Is it recommended to use one among the other one?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Integer(num)will throw anArgumentErrorexception if num isn’t a valid integer (you can specify the base).num.to_iwill convert as much as it can.For example: