Ruby/String/next

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

Содержание

Call next function from string class

"Test".next



Call next function on returning result from reverse

"Test".upcase.reverse.next



Chain calls of next together

"0".next.next.next # => "3"



next method from Integer.

# (The Date, Generator, Integer, and String classes all have next methods.)
# You can even use a character code via chr with next:
120.chr # => "x"
120.chr.next # => "y"



next works for numbers represented as strings

"2007".next # => "2008"



number.next

2008.next # => 2009



string.next adds a character when it reaches a boundary, or adds a digit or decimal place when appropriate

puts "z".next
puts "zzzz".next
puts "999.0".next
puts "999".next



string.next is based on the character set in use

" ".next # => "!"