Method: String#increment

Defined in:
lib/webget_ramp/string.rb

#increment(step = 1) ⇒ Object

Increment the rightmost natural number

Example

'foo5bar'.increment => 'foo4bar'
'foo5bar'.increment(3) => 'foo8bar'
'foo9bar'.increment => 'foo10bar'
  • see String#decrement



101
102
103
# File 'lib/webget_ramp/string.rb', line 101

def increment(step=1)
 self=~/\d+/ ? $`+($&.to_i+step).to_s+$' : self
end