Ruby: Increasing the Number of Type Strings

I work with an API that requires me to pass numbers as strings. I need to increment the counter on every call.

I am using the following code:

days = days.to_i
days += 1
days = days.to_s

It works, but it seems messy. Is there another way to do this in Ruby?

+4
source share
1 answer

Yes there is. You can do:

days = days.next

or

days = days.succ

Or you can use bang (!) Methods:

days.next!

or

days.succ!
+5
source

Source: https://habr.com/ru/post/1568317/


All Articles