Skip to content

Instantly share code, notes, and snippets.

@taiansu
Created November 7, 2012 08:12
Show Gist options
  • Save taiansu/4030139 to your computer and use it in GitHub Desktop.
Save taiansu/4030139 to your computer and use it in GitHub Desktop.
Running Number in Ruby
class RunningNumber
attr_accessor :prefix, :current
def initialize(prefix = 'RUN', current = '000000')
@prefix = prefix
@current = current
end
def current
@prefix + @current
end
def next
@prefix + @current.next!
end
def reset_current_to(current = '000000')
@current = current
puts "RunningNumber has reset to " + @prefix + @current
end
alias_method :reset, :reset_current_to
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment