简体   繁体   中英

how to increase count by 1 in ruby?

I am using the below code to get the number of records.

self.size.to_s

How can i add '1' to the size from above?

Integer#next

self.size.next.to_s

(self.size + 1).to_s #像这样

You can either add it before converting to string

(self.size + 1).to_s

Or if you already have a string

"2".to_i + 1

Combined this could be something like

self.size.to_s.to_i + 1

but that is hardly practical

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM