Created
November 7, 2012 08:12
-
-
Save taiansu/4030139 to your computer and use it in GitHub Desktop.
Running Number in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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