How to convert a whole string without using the ruby ​​method 'to_i'

advertisements

I want to convert given string into integer without using ruby to_i method.

Basically, I want to know how to_i was implemented or what is the best way to do that. Eg :

a = '1234'

result
a = 1234

Thanks in advance


You can do this by following

2.1.0 :031 > str = "12345"
 => "12345"
2.1.0 :032 > Integer(str) rescue 0
 => 12345